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

Side by Side Diff: chrome/browser/sync/engine/syncer_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
« no previous file with comments | « chrome/browser/sync/engine/syncer.cc ('k') | chrome/browser/sync/engine/syncer_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Syncer unit tests. Unfortunately a lot of these tests 5 // Syncer unit tests. Unfortunately a lot of these tests
6 // are outdated and need to be reworked and updated. 6 // are outdated and need to be reworked and updated.
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <limits> 9 #include <limits>
10 #include <list> 10 #include <list>
11 #include <map> 11 #include <map>
12 #include <set> 12 #include <set>
13 #include <string> 13 #include <string>
14 14
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/stringprintf.h" 17 #include "base/stringprintf.h"
18 #include "base/string_number_conversions.h" 18 #include "base/string_number_conversions.h"
19 #include "base/tracked.h"
19 #include "build/build_config.h" 20 #include "build/build_config.h"
20 #include "chrome/browser/sync/engine/conflict_resolver.h" 21 #include "chrome/browser/sync/engine/conflict_resolver.h"
21 #include "chrome/browser/sync/engine/get_commit_ids_command.h" 22 #include "chrome/browser/sync/engine/get_commit_ids_command.h"
22 #include "chrome/browser/sync/engine/model_safe_worker.h" 23 #include "chrome/browser/sync/engine/model_safe_worker.h"
23 #include "chrome/browser/sync/engine/net/server_connection_manager.h" 24 #include "chrome/browser/sync/engine/net/server_connection_manager.h"
24 #include "chrome/browser/sync/engine/process_updates_command.h" 25 #include "chrome/browser/sync/engine/process_updates_command.h"
25 #include "chrome/browser/sync/engine/syncer.h" 26 #include "chrome/browser/sync/engine/syncer.h"
26 #include "chrome/browser/sync/engine/syncer_proto_util.h" 27 #include "chrome/browser/sync/engine/syncer_proto_util.h"
27 #include "chrome/browser/sync/engine/syncer_util.h" 28 #include "chrome/browser/sync/engine/syncer_util.h"
28 #include "chrome/browser/sync/engine/syncproto.h" 29 #include "chrome/browser/sync/engine/syncproto.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 listeners.push_back(this); 190 listeners.push_back(this);
190 context_.reset(new SyncSessionContext(mock_server_.get(), 191 context_.reset(new SyncSessionContext(mock_server_.get(),
191 syncdb_.manager(), this, listeners)); 192 syncdb_.manager(), this, listeners));
192 context_->set_account_name(syncdb_.name()); 193 context_->set_account_name(syncdb_.name());
193 ASSERT_FALSE(context_->resolver()); 194 ASSERT_FALSE(context_->resolver());
194 syncer_ = new Syncer(); 195 syncer_ = new Syncer();
195 session_.reset(MakeSession()); 196 session_.reset(MakeSession());
196 197
197 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 198 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
198 CHECK(dir.good()); 199 CHECK(dir.good());
199 ReadTransaction trans(dir, __FILE__, __LINE__); 200 ReadTransaction trans(dir, FROM_HERE);
200 syncable::Directory::ChildHandles children; 201 syncable::Directory::ChildHandles children;
201 dir->GetChildHandlesById(&trans, trans.root_id(), &children); 202 dir->GetChildHandlesById(&trans, trans.root_id(), &children);
202 ASSERT_TRUE(0 == children.size()); 203 ASSERT_TRUE(0 == children.size());
203 saw_syncer_event_ = false; 204 saw_syncer_event_ = false;
204 root_id_ = TestIdFactory::root(); 205 root_id_ = TestIdFactory::root();
205 parent_id_ = ids_.MakeServer("parent id"); 206 parent_id_ = ids_.MakeServer("parent id");
206 child_id_ = ids_.MakeServer("child id"); 207 child_id_ = ids_.MakeServer("child id");
207 } 208 }
208 209
209 virtual void TearDown() { 210 virtual void TearDown() {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 275
275 static const CommitOrderingTest LAST_COMMIT_ITEM; 276 static const CommitOrderingTest LAST_COMMIT_ITEM;
276 }; 277 };
277 278
278 void RunCommitOrderingTest(CommitOrderingTest* test) { 279 void RunCommitOrderingTest(CommitOrderingTest* test) {
279 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 280 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
280 ASSERT_TRUE(dir.good()); 281 ASSERT_TRUE(dir.good());
281 282
282 map<int, syncable::Id> expected_positions; 283 map<int, syncable::Id> expected_positions;
283 { // Transaction scope. 284 { // Transaction scope.
284 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 285 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
285 while (!test->id.IsRoot()) { 286 while (!test->id.IsRoot()) {
286 if (test->commit_index >= 0) { 287 if (test->commit_index >= 0) {
287 map<int, syncable::Id>::value_type entry(test->commit_index, 288 map<int, syncable::Id>::value_type entry(test->commit_index,
288 test->id); 289 test->id);
289 bool double_position = !expected_positions.insert(entry).second; 290 bool double_position = !expected_positions.insert(entry).second;
290 ASSERT_FALSE(double_position) << "Two id's expected at one position"; 291 ASSERT_FALSE(double_position) << "Two id's expected at one position";
291 } 292 }
292 string utf8_name = test->id.GetServerId(); 293 string utf8_name = test->id.GetServerId();
293 string name(utf8_name.begin(), utf8_name.end()); 294 string name(utf8_name.begin(), utf8_name.end());
294 MutableEntry entry(&trans, CREATE, test->parent_id, name); 295 MutableEntry entry(&trans, CREATE, test->parent_id, name);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 EXPECT_TRUE(expected_positions[i] == mock_server_->committed_ids()[i]); 341 EXPECT_TRUE(expected_positions[i] == mock_server_->committed_ids()[i]);
341 } 342 }
342 } 343 }
343 344
344 void DoTruncationTest(const ScopedDirLookup& dir, 345 void DoTruncationTest(const ScopedDirLookup& dir,
345 const vector<int64>& unsynced_handle_view, 346 const vector<int64>& unsynced_handle_view,
346 const vector<syncable::Id>& expected_id_order) { 347 const vector<syncable::Id>& expected_id_order) {
347 // The expected order is "x", "b", "c", "e", truncated appropriately. 348 // The expected order is "x", "b", "c", "e", truncated appropriately.
348 for (size_t limit = expected_id_order.size() + 2; limit > 0; --limit) { 349 for (size_t limit = expected_id_order.size() + 2; limit > 0; --limit) {
349 StatusController* status = session_->status_controller(); 350 StatusController* status = session_->status_controller();
350 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 351 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
351 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans); 352 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans);
352 status->set_unsynced_handles(unsynced_handle_view); 353 status->set_unsynced_handles(unsynced_handle_view);
353 354
354 ModelSafeRoutingInfo routes; 355 ModelSafeRoutingInfo routes;
355 GetModelSafeRoutingInfo(&routes); 356 GetModelSafeRoutingInfo(&routes);
356 GetCommitIdsCommand command(limit); 357 GetCommitIdsCommand command(limit);
357 command.BuildCommitIds(session_->status_controller()->unsynced_handles(), 358 command.BuildCommitIds(session_->status_controller()->unsynced_handles(),
358 session_->write_transaction(), routes); 359 session_->write_transaction(), routes);
359 vector<syncable::Id> output = 360 vector<syncable::Id> output =
360 command.ordered_commit_set_->GetAllCommitIds(); 361 command.ordered_commit_set_->GetAllCommitIds();
(...skipping 20 matching lines...) Expand all
381 int64 CreateUnsyncedDirectory(const string& entry_name, 382 int64 CreateUnsyncedDirectory(const string& entry_name,
382 const string& idstring) { 383 const string& idstring) {
383 return CreateUnsyncedDirectory(entry_name, 384 return CreateUnsyncedDirectory(entry_name,
384 syncable::Id::CreateFromServerId(idstring)); 385 syncable::Id::CreateFromServerId(idstring));
385 } 386 }
386 387
387 int64 CreateUnsyncedDirectory(const string& entry_name, 388 int64 CreateUnsyncedDirectory(const string& entry_name,
388 const syncable::Id& id) { 389 const syncable::Id& id) {
389 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 390 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
390 EXPECT_TRUE(dir.good()); 391 EXPECT_TRUE(dir.good());
391 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 392 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
392 MutableEntry entry(&wtrans, syncable::CREATE, wtrans.root_id(), 393 MutableEntry entry(&wtrans, syncable::CREATE, wtrans.root_id(),
393 entry_name); 394 entry_name);
394 EXPECT_TRUE(entry.good()); 395 EXPECT_TRUE(entry.good());
395 entry.Put(syncable::IS_UNSYNCED, true); 396 entry.Put(syncable::IS_UNSYNCED, true);
396 entry.Put(syncable::IS_DIR, true); 397 entry.Put(syncable::IS_DIR, true);
397 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 398 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
398 entry.Put(syncable::BASE_VERSION, id.ServerKnows() ? 1 : 0); 399 entry.Put(syncable::BASE_VERSION, id.ServerKnows() ? 1 : 0);
399 entry.Put(syncable::ID, id); 400 entry.Put(syncable::ID, id);
400 return entry.Get(META_HANDLE); 401 return entry.Get(META_HANDLE);
401 } 402 }
402 403
403 void EnableDatatype(syncable::ModelType model_type) { 404 void EnableDatatype(syncable::ModelType model_type) {
404 enabled_datatypes_[model_type] = true; 405 enabled_datatypes_[model_type] = true;
405 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_); 406 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_);
406 } 407 }
407 408
408 void DisableDatatype(syncable::ModelType model_type) { 409 void DisableDatatype(syncable::ModelType model_type) {
409 enabled_datatypes_[model_type] = false; 410 enabled_datatypes_[model_type] = false;
410 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_); 411 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_);
411 } 412 }
412 413
413 template<typename FieldType, typename ValueType> 414 template<typename FieldType, typename ValueType>
414 ValueType GetField(int64 metahandle, FieldType field, 415 ValueType GetField(int64 metahandle, FieldType field,
415 ValueType default_value) const { 416 ValueType default_value) const {
416 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 417 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
417 EXPECT_TRUE(dir.good()); 418 EXPECT_TRUE(dir.good());
418 ReadTransaction trans(dir, __FILE__, __LINE__); 419 ReadTransaction trans(dir, FROM_HERE);
419 Entry entry(&trans, GET_BY_HANDLE, metahandle); 420 Entry entry(&trans, GET_BY_HANDLE, metahandle);
420 EXPECT_TRUE(entry.good()); 421 EXPECT_TRUE(entry.good());
421 if (!entry.good()) { 422 if (!entry.good()) {
422 return default_value; 423 return default_value;
423 } 424 }
424 EXPECT_EQ(metahandle, entry.Get(META_HANDLE)); 425 EXPECT_EQ(metahandle, entry.Get(META_HANDLE));
425 return entry.Get(field); 426 return entry.Get(field);
426 } 427 }
427 428
428 // Helper getters that work without a transaction, to reduce boilerplate. 429 // Helper getters that work without a transaction, to reduce boilerplate.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 482
482 DISALLOW_COPY_AND_ASSIGN(SyncerTest); 483 DISALLOW_COPY_AND_ASSIGN(SyncerTest);
483 }; 484 };
484 485
485 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { 486 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) {
486 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 487 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
487 ASSERT_TRUE(dir.good()); 488 ASSERT_TRUE(dir.good());
488 { 489 {
489 Syncer::UnsyncedMetaHandles handles; 490 Syncer::UnsyncedMetaHandles handles;
490 { 491 {
491 ReadTransaction trans(dir, __FILE__, __LINE__); 492 ReadTransaction trans(dir, FROM_HERE);
492 SyncerUtil::GetUnsyncedEntries(&trans, &handles); 493 SyncerUtil::GetUnsyncedEntries(&trans, &handles);
493 } 494 }
494 ASSERT_TRUE(0 == handles.size()); 495 ASSERT_TRUE(0 == handles.size());
495 } 496 }
496 // TODO(sync): When we can dynamically connect and disconnect the mock 497 // TODO(sync): When we can dynamically connect and disconnect the mock
497 // ServerConnectionManager test disconnected GetUnsyncedEntries here. It's a 498 // ServerConnectionManager test disconnected GetUnsyncedEntries here. It's a
498 // regression for a very old bug. 499 // regression for a very old bug.
499 } 500 }
500 501
501 TEST_F(SyncerTest, GetCommitIdsCommandTruncates) { 502 TEST_F(SyncerTest, GetCommitIdsCommandTruncates) {
502 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 503 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
503 ASSERT_TRUE(dir.good()); 504 ASSERT_TRUE(dir.good());
504 int64 handle_c = CreateUnsyncedDirectory("C", ids_.MakeLocal("c")); 505 int64 handle_c = CreateUnsyncedDirectory("C", ids_.MakeLocal("c"));
505 int64 handle_x = CreateUnsyncedDirectory("X", ids_.MakeLocal("x")); 506 int64 handle_x = CreateUnsyncedDirectory("X", ids_.MakeLocal("x"));
506 int64 handle_b = CreateUnsyncedDirectory("B", ids_.MakeLocal("b")); 507 int64 handle_b = CreateUnsyncedDirectory("B", ids_.MakeLocal("b"));
507 int64 handle_d = CreateUnsyncedDirectory("D", ids_.MakeLocal("d")); 508 int64 handle_d = CreateUnsyncedDirectory("D", ids_.MakeLocal("d"));
508 int64 handle_e = CreateUnsyncedDirectory("E", ids_.MakeLocal("e")); 509 int64 handle_e = CreateUnsyncedDirectory("E", ids_.MakeLocal("e"));
509 { 510 {
510 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 511 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
511 MutableEntry entry_x(&wtrans, GET_BY_HANDLE, handle_x); 512 MutableEntry entry_x(&wtrans, GET_BY_HANDLE, handle_x);
512 MutableEntry entry_b(&wtrans, GET_BY_HANDLE, handle_b); 513 MutableEntry entry_b(&wtrans, GET_BY_HANDLE, handle_b);
513 MutableEntry entry_c(&wtrans, GET_BY_HANDLE, handle_c); 514 MutableEntry entry_c(&wtrans, GET_BY_HANDLE, handle_c);
514 MutableEntry entry_d(&wtrans, GET_BY_HANDLE, handle_d); 515 MutableEntry entry_d(&wtrans, GET_BY_HANDLE, handle_d);
515 MutableEntry entry_e(&wtrans, GET_BY_HANDLE, handle_e); 516 MutableEntry entry_e(&wtrans, GET_BY_HANDLE, handle_e);
516 entry_x.Put(SPECIFICS, DefaultBookmarkSpecifics()); 517 entry_x.Put(SPECIFICS, DefaultBookmarkSpecifics());
517 entry_b.Put(SPECIFICS, DefaultBookmarkSpecifics()); 518 entry_b.Put(SPECIFICS, DefaultBookmarkSpecifics());
518 entry_c.Put(SPECIFICS, DefaultBookmarkSpecifics()); 519 entry_c.Put(SPECIFICS, DefaultBookmarkSpecifics());
519 entry_d.Put(SPECIFICS, DefaultBookmarkSpecifics()); 520 entry_d.Put(SPECIFICS, DefaultBookmarkSpecifics());
520 entry_e.Put(SPECIFICS, DefaultBookmarkSpecifics()); 521 entry_e.Put(SPECIFICS, DefaultBookmarkSpecifics());
(...skipping 17 matching lines...) Expand all
538 } 539 }
539 540
540 // TODO(chron): More corner case unit tests around validation. 541 // TODO(chron): More corner case unit tests around validation.
541 TEST_F(SyncerTest, TestCommitMetahandleIterator) { 542 TEST_F(SyncerTest, TestCommitMetahandleIterator) {
542 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 543 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
543 ASSERT_TRUE(dir.good()); 544 ASSERT_TRUE(dir.good());
544 StatusController* status = session_->status_controller(); 545 StatusController* status = session_->status_controller();
545 const vector<int64>& unsynced(status->unsynced_handles()); 546 const vector<int64>& unsynced(status->unsynced_handles());
546 547
547 { 548 {
548 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 549 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
549 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans); 550 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans);
550 551
551 sessions::OrderedCommitSet commit_set(session_->routing_info()); 552 sessions::OrderedCommitSet commit_set(session_->routing_info());
552 GetCommitIdsCommand::CommitMetahandleIterator iterator(unsynced, &wtrans, 553 GetCommitIdsCommand::CommitMetahandleIterator iterator(unsynced, &wtrans,
553 &commit_set); 554 &commit_set);
554 EXPECT_FALSE(iterator.Valid()); 555 EXPECT_FALSE(iterator.Valid());
555 EXPECT_FALSE(iterator.Increment()); 556 EXPECT_FALSE(iterator.Increment());
556 } 557 }
557 558
558 { 559 {
559 vector<int64> session_metahandles; 560 vector<int64> session_metahandles;
560 session_metahandles.push_back(CreateUnsyncedDirectory("test1", "testid1")); 561 session_metahandles.push_back(CreateUnsyncedDirectory("test1", "testid1"));
561 session_metahandles.push_back(CreateUnsyncedDirectory("test2", "testid2")); 562 session_metahandles.push_back(CreateUnsyncedDirectory("test2", "testid2"));
562 session_metahandles.push_back(CreateUnsyncedDirectory("test3", "testid3")); 563 session_metahandles.push_back(CreateUnsyncedDirectory("test3", "testid3"));
563 status->set_unsynced_handles(session_metahandles); 564 status->set_unsynced_handles(session_metahandles);
564 565
565 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 566 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
566 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans); 567 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans);
567 sessions::OrderedCommitSet commit_set(session_->routing_info()); 568 sessions::OrderedCommitSet commit_set(session_->routing_info());
568 GetCommitIdsCommand::CommitMetahandleIterator iterator(unsynced, &wtrans, 569 GetCommitIdsCommand::CommitMetahandleIterator iterator(unsynced, &wtrans,
569 &commit_set); 570 &commit_set);
570 571
571 EXPECT_TRUE(iterator.Valid()); 572 EXPECT_TRUE(iterator.Valid());
572 EXPECT_TRUE(iterator.Current() == session_metahandles[0]); 573 EXPECT_TRUE(iterator.Current() == session_metahandles[0]);
573 EXPECT_TRUE(iterator.Increment()); 574 EXPECT_TRUE(iterator.Increment());
574 575
575 EXPECT_TRUE(iterator.Valid()); 576 EXPECT_TRUE(iterator.Valid());
576 EXPECT_TRUE(iterator.Current() == session_metahandles[1]); 577 EXPECT_TRUE(iterator.Current() == session_metahandles[1]);
577 EXPECT_TRUE(iterator.Increment()); 578 EXPECT_TRUE(iterator.Increment());
578 579
579 EXPECT_TRUE(iterator.Valid()); 580 EXPECT_TRUE(iterator.Valid());
580 EXPECT_TRUE(iterator.Current() == session_metahandles[2]); 581 EXPECT_TRUE(iterator.Current() == session_metahandles[2]);
581 EXPECT_FALSE(iterator.Increment()); 582 EXPECT_FALSE(iterator.Increment());
582 583
583 EXPECT_FALSE(iterator.Valid()); 584 EXPECT_FALSE(iterator.Valid());
584 } 585 }
585 } 586 }
586 587
587 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) { 588 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) {
588 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 589 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
589 ASSERT_TRUE(dir.good()); 590 ASSERT_TRUE(dir.good());
590 { 591 {
591 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 592 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
592 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), 593 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(),
593 "Pete"); 594 "Pete");
594 ASSERT_TRUE(parent.good()); 595 ASSERT_TRUE(parent.good());
595 parent.Put(syncable::IS_UNSYNCED, true); 596 parent.Put(syncable::IS_UNSYNCED, true);
596 parent.Put(syncable::IS_DIR, true); 597 parent.Put(syncable::IS_DIR, true);
597 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 598 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
598 parent.Put(syncable::BASE_VERSION, 1); 599 parent.Put(syncable::BASE_VERSION, 1);
599 parent.Put(syncable::ID, parent_id_); 600 parent.Put(syncable::ID, parent_id_);
600 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete"); 601 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete");
601 ASSERT_TRUE(child.good()); 602 ASSERT_TRUE(child.good());
602 child.Put(syncable::ID, child_id_); 603 child.Put(syncable::ID, child_id_);
603 child.Put(syncable::BASE_VERSION, 1); 604 child.Put(syncable::BASE_VERSION, 1);
604 WriteTestDataToEntry(&wtrans, &child); 605 WriteTestDataToEntry(&wtrans, &child);
605 } 606 }
606 607
607 StatusController* status = session_->status_controller(); 608 StatusController* status = session_->status_controller();
608 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 609 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
609 EXPECT_TRUE(2 == status->unsynced_handles().size()); 610 EXPECT_TRUE(2 == status->unsynced_handles().size());
610 ASSERT_TRUE(2 == mock_server_->committed_ids().size()); 611 ASSERT_TRUE(2 == mock_server_->committed_ids().size());
611 // If this test starts failing, be aware other sort orders could be valid. 612 // If this test starts failing, be aware other sort orders could be valid.
612 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 613 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
613 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 614 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
614 { 615 {
615 ReadTransaction rt(dir, __FILE__, __LINE__); 616 ReadTransaction rt(dir, FROM_HERE);
616 Entry entry(&rt, syncable::GET_BY_ID, child_id_); 617 Entry entry(&rt, syncable::GET_BY_ID, child_id_);
617 ASSERT_TRUE(entry.good()); 618 ASSERT_TRUE(entry.good());
618 VerifyTestDataInEntry(&rt, &entry); 619 VerifyTestDataInEntry(&rt, &entry);
619 } 620 }
620 } 621 }
621 622
622 TEST_F(SyncerTest, TestPurgeWhileUnsynced) { 623 TEST_F(SyncerTest, TestPurgeWhileUnsynced) {
623 // Similar to above, but throw a purge operation into the mix. Bug 49278. 624 // Similar to above, but throw a purge operation into the mix. Bug 49278.
624 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 625 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
625 ASSERT_TRUE(dir.good()); 626 ASSERT_TRUE(dir.good());
626 syncable::Id pref_node_id = TestIdFactory::MakeServer("Tim"); 627 syncable::Id pref_node_id = TestIdFactory::MakeServer("Tim");
627 { 628 {
628 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 629 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
629 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "Pete"); 630 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "Pete");
630 ASSERT_TRUE(parent.good()); 631 ASSERT_TRUE(parent.good());
631 parent.Put(syncable::IS_UNSYNCED, true); 632 parent.Put(syncable::IS_UNSYNCED, true);
632 parent.Put(syncable::IS_DIR, true); 633 parent.Put(syncable::IS_DIR, true);
633 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 634 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
634 parent.Put(syncable::BASE_VERSION, 1); 635 parent.Put(syncable::BASE_VERSION, 1);
635 parent.Put(syncable::ID, parent_id_); 636 parent.Put(syncable::ID, parent_id_);
636 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete"); 637 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete");
637 ASSERT_TRUE(child.good()); 638 ASSERT_TRUE(child.good());
638 child.Put(syncable::ID, child_id_); 639 child.Put(syncable::ID, child_id_);
(...skipping 14 matching lines...) Expand all
653 dir->PurgeEntriesWithTypeIn(types_to_purge); 654 dir->PurgeEntriesWithTypeIn(types_to_purge);
654 655
655 StatusController* status = session_->status_controller(); 656 StatusController* status = session_->status_controller();
656 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 657 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
657 EXPECT_EQ(2U, status->unsynced_handles().size()); 658 EXPECT_EQ(2U, status->unsynced_handles().size());
658 ASSERT_EQ(2U, mock_server_->committed_ids().size()); 659 ASSERT_EQ(2U, mock_server_->committed_ids().size());
659 // If this test starts failing, be aware other sort orders could be valid. 660 // If this test starts failing, be aware other sort orders could be valid.
660 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 661 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
661 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 662 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
662 { 663 {
663 ReadTransaction rt(dir, __FILE__, __LINE__); 664 ReadTransaction rt(dir, FROM_HERE);
664 Entry entry(&rt, syncable::GET_BY_ID, child_id_); 665 Entry entry(&rt, syncable::GET_BY_ID, child_id_);
665 ASSERT_TRUE(entry.good()); 666 ASSERT_TRUE(entry.good());
666 VerifyTestDataInEntry(&rt, &entry); 667 VerifyTestDataInEntry(&rt, &entry);
667 } 668 }
668 dir->SaveChanges(); 669 dir->SaveChanges();
669 { 670 {
670 ReadTransaction rt(dir, __FILE__, __LINE__); 671 ReadTransaction rt(dir, FROM_HERE);
671 Entry entry(&rt, syncable::GET_BY_ID, pref_node_id); 672 Entry entry(&rt, syncable::GET_BY_ID, pref_node_id);
672 ASSERT_FALSE(entry.good()); 673 ASSERT_FALSE(entry.good());
673 } 674 }
674 } 675 }
675 676
676 TEST_F(SyncerTest, TestPurgeWhileUnapplied) { 677 TEST_F(SyncerTest, TestPurgeWhileUnapplied) {
677 // Similar to above, but for unapplied items. Bug 49278. 678 // Similar to above, but for unapplied items. Bug 49278.
678 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 679 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
679 ASSERT_TRUE(dir.good()); 680 ASSERT_TRUE(dir.good());
680 { 681 {
681 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 682 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
682 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "Pete"); 683 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "Pete");
683 ASSERT_TRUE(parent.good()); 684 ASSERT_TRUE(parent.good());
684 parent.Put(syncable::IS_UNAPPLIED_UPDATE, true); 685 parent.Put(syncable::IS_UNAPPLIED_UPDATE, true);
685 parent.Put(syncable::IS_DIR, true); 686 parent.Put(syncable::IS_DIR, true);
686 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 687 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
687 parent.Put(syncable::BASE_VERSION, 1); 688 parent.Put(syncable::BASE_VERSION, 1);
688 parent.Put(syncable::ID, parent_id_); 689 parent.Put(syncable::ID, parent_id_);
689 } 690 }
690 691
691 std::set<syncable::ModelType> types_to_purge; 692 std::set<syncable::ModelType> types_to_purge;
692 types_to_purge.insert(syncable::BOOKMARKS); 693 types_to_purge.insert(syncable::BOOKMARKS);
693 dir->PurgeEntriesWithTypeIn(types_to_purge); 694 dir->PurgeEntriesWithTypeIn(types_to_purge);
694 695
695 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 696 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
696 dir->SaveChanges(); 697 dir->SaveChanges();
697 { 698 {
698 ReadTransaction rt(dir, __FILE__, __LINE__); 699 ReadTransaction rt(dir, FROM_HERE);
699 Entry entry(&rt, syncable::GET_BY_ID, parent_id_); 700 Entry entry(&rt, syncable::GET_BY_ID, parent_id_);
700 ASSERT_FALSE(entry.good()); 701 ASSERT_FALSE(entry.good());
701 } 702 }
702 } 703 }
703 704
704 TEST_F(SyncerTest, TestCommitListOrderingTwoItemsTall) { 705 TEST_F(SyncerTest, TestCommitListOrderingTwoItemsTall) {
705 CommitOrderingTest items[] = { 706 CommitOrderingTest items[] = {
706 {1, ids_.FromNumber(-1001), ids_.FromNumber(-1000)}, 707 {1, ids_.FromNumber(-1001), ids_.FromNumber(-1000)},
707 {0, ids_.FromNumber(-1000), ids_.FromNumber(0)}, 708 {0, ids_.FromNumber(-1000), ids_.FromNumber(0)},
708 CommitOrderingTest::LAST_COMMIT_ITEM, 709 CommitOrderingTest::LAST_COMMIT_ITEM,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 RunCommitOrderingTest(items); 830 RunCommitOrderingTest(items);
830 } 831 }
831 832
832 TEST_F(SyncerTest, TestCommitListOrderingWithNesting) { 833 TEST_F(SyncerTest, TestCommitListOrderingWithNesting) {
833 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 834 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
834 ASSERT_TRUE(dir.good()); 835 ASSERT_TRUE(dir.good());
835 int64 now_server_time = ClientTimeToServerTime(syncable::Now()); 836 int64 now_server_time = ClientTimeToServerTime(syncable::Now());
836 int64 now_minus_2h = ServerTimeToClientTime(now_server_time - 7200000); 837 int64 now_minus_2h = ServerTimeToClientTime(now_server_time - 7200000);
837 838
838 { 839 {
839 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 840 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
840 { 841 {
841 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), 842 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(),
842 "Bob"); 843 "Bob");
843 ASSERT_TRUE(parent.good()); 844 ASSERT_TRUE(parent.good());
844 parent.Put(syncable::IS_UNSYNCED, true); 845 parent.Put(syncable::IS_UNSYNCED, true);
845 parent.Put(syncable::IS_DIR, true); 846 parent.Put(syncable::IS_DIR, true);
846 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 847 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
847 parent.Put(syncable::ID, ids_.FromNumber(100)); 848 parent.Put(syncable::ID, ids_.FromNumber(100));
848 parent.Put(syncable::BASE_VERSION, 1); 849 parent.Put(syncable::BASE_VERSION, 1);
849 MutableEntry child(&wtrans, syncable::CREATE, ids_.FromNumber(100), 850 MutableEntry child(&wtrans, syncable::CREATE, ids_.FromNumber(100),
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 std::sort(commit_ids.begin() + 3, commit_ids.end()); 913 std::sort(commit_ids.begin() + 3, commit_ids.end());
913 EXPECT_TRUE(ids_.FromNumber(103) == commit_ids[3]); 914 EXPECT_TRUE(ids_.FromNumber(103) == commit_ids[3]);
914 EXPECT_TRUE(ids_.FromNumber(104) == commit_ids[4]); 915 EXPECT_TRUE(ids_.FromNumber(104) == commit_ids[4]);
915 EXPECT_TRUE(ids_.FromNumber(105) == commit_ids[5]); 916 EXPECT_TRUE(ids_.FromNumber(105) == commit_ids[5]);
916 } 917 }
917 918
918 TEST_F(SyncerTest, TestCommitListOrderingWithNewItems) { 919 TEST_F(SyncerTest, TestCommitListOrderingWithNewItems) {
919 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 920 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
920 ASSERT_TRUE(dir.good()); 921 ASSERT_TRUE(dir.good());
921 { 922 {
922 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 923 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
923 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "1"); 924 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "1");
924 ASSERT_TRUE(parent.good()); 925 ASSERT_TRUE(parent.good());
925 parent.Put(syncable::IS_UNSYNCED, true); 926 parent.Put(syncable::IS_UNSYNCED, true);
926 parent.Put(syncable::IS_DIR, true); 927 parent.Put(syncable::IS_DIR, true);
927 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 928 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
928 parent.Put(syncable::ID, parent_id_); 929 parent.Put(syncable::ID, parent_id_);
929 MutableEntry child(&wtrans, syncable::CREATE, wtrans.root_id(), "2"); 930 MutableEntry child(&wtrans, syncable::CREATE, wtrans.root_id(), "2");
930 ASSERT_TRUE(child.good()); 931 ASSERT_TRUE(child.good());
931 child.Put(syncable::IS_UNSYNCED, true); 932 child.Put(syncable::IS_UNSYNCED, true);
932 child.Put(syncable::IS_DIR, true); 933 child.Put(syncable::IS_DIR, true);
933 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 934 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
934 child.Put(syncable::ID, child_id_); 935 child.Put(syncable::ID, child_id_);
935 parent.Put(syncable::BASE_VERSION, 1); 936 parent.Put(syncable::BASE_VERSION, 1);
936 child.Put(syncable::BASE_VERSION, 1); 937 child.Put(syncable::BASE_VERSION, 1);
937 } 938 }
938 { 939 {
939 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 940 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
940 MutableEntry parent(&wtrans, syncable::CREATE, parent_id_, "A"); 941 MutableEntry parent(&wtrans, syncable::CREATE, parent_id_, "A");
941 ASSERT_TRUE(parent.good()); 942 ASSERT_TRUE(parent.good());
942 parent.Put(syncable::IS_UNSYNCED, true); 943 parent.Put(syncable::IS_UNSYNCED, true);
943 parent.Put(syncable::IS_DIR, true); 944 parent.Put(syncable::IS_DIR, true);
944 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 945 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
945 parent.Put(syncable::ID, ids_.FromNumber(102)); 946 parent.Put(syncable::ID, ids_.FromNumber(102));
946 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "B"); 947 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "B");
947 ASSERT_TRUE(child.good()); 948 ASSERT_TRUE(child.good());
948 child.Put(syncable::IS_UNSYNCED, true); 949 child.Put(syncable::IS_UNSYNCED, true);
949 child.Put(syncable::IS_DIR, true); 950 child.Put(syncable::IS_DIR, true);
950 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 951 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
951 child.Put(syncable::ID, ids_.FromNumber(-103)); 952 child.Put(syncable::ID, ids_.FromNumber(-103));
952 parent.Put(syncable::BASE_VERSION, 1); 953 parent.Put(syncable::BASE_VERSION, 1);
953 } 954 }
954 { 955 {
955 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 956 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
956 MutableEntry parent(&wtrans, syncable::CREATE, child_id_, "A"); 957 MutableEntry parent(&wtrans, syncable::CREATE, child_id_, "A");
957 ASSERT_TRUE(parent.good()); 958 ASSERT_TRUE(parent.good());
958 parent.Put(syncable::IS_UNSYNCED, true); 959 parent.Put(syncable::IS_UNSYNCED, true);
959 parent.Put(syncable::IS_DIR, true); 960 parent.Put(syncable::IS_DIR, true);
960 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 961 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
961 parent.Put(syncable::ID, ids_.FromNumber(-104)); 962 parent.Put(syncable::ID, ids_.FromNumber(-104));
962 MutableEntry child(&wtrans, syncable::CREATE, child_id_, "B"); 963 MutableEntry child(&wtrans, syncable::CREATE, child_id_, "B");
963 ASSERT_TRUE(child.good()); 964 ASSERT_TRUE(child.good());
964 child.Put(syncable::IS_UNSYNCED, true); 965 child.Put(syncable::IS_UNSYNCED, true);
965 child.Put(syncable::IS_DIR, true); 966 child.Put(syncable::IS_DIR, true);
(...skipping 14 matching lines...) Expand all
980 EXPECT_TRUE(ids_.FromNumber(105) == mock_server_->committed_ids()[5]); 981 EXPECT_TRUE(ids_.FromNumber(105) == mock_server_->committed_ids()[5]);
981 } 982 }
982 983
983 TEST_F(SyncerTest, TestCommitListOrderingCounterexample) { 984 TEST_F(SyncerTest, TestCommitListOrderingCounterexample) {
984 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 985 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
985 ASSERT_TRUE(dir.good()); 986 ASSERT_TRUE(dir.good());
986 987
987 syncable::Id child2_id = ids_.NewServerId(); 988 syncable::Id child2_id = ids_.NewServerId();
988 989
989 { 990 {
990 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 991 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
991 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "P"); 992 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "P");
992 ASSERT_TRUE(parent.good()); 993 ASSERT_TRUE(parent.good());
993 parent.Put(syncable::IS_UNSYNCED, true); 994 parent.Put(syncable::IS_UNSYNCED, true);
994 parent.Put(syncable::IS_DIR, true); 995 parent.Put(syncable::IS_DIR, true);
995 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 996 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
996 parent.Put(syncable::ID, parent_id_); 997 parent.Put(syncable::ID, parent_id_);
997 MutableEntry child1(&wtrans, syncable::CREATE, parent_id_, "1"); 998 MutableEntry child1(&wtrans, syncable::CREATE, parent_id_, "1");
998 ASSERT_TRUE(child1.good()); 999 ASSERT_TRUE(child1.good());
999 child1.Put(syncable::IS_UNSYNCED, true); 1000 child1.Put(syncable::IS_UNSYNCED, true);
1000 child1.Put(syncable::ID, child_id_); 1001 child1.Put(syncable::ID, child_id_);
(...skipping 20 matching lines...) Expand all
1021 1022
1022 TEST_F(SyncerTest, TestCommitListOrderingAndNewParent) { 1023 TEST_F(SyncerTest, TestCommitListOrderingAndNewParent) {
1023 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 1024 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
1024 ASSERT_TRUE(dir.good()); 1025 ASSERT_TRUE(dir.good());
1025 1026
1026 string parent1_name = "1"; 1027 string parent1_name = "1";
1027 string parent2_name = "A"; 1028 string parent2_name = "A";
1028 string child_name = "B"; 1029 string child_name = "B";
1029 1030
1030 { 1031 {
1031 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 1032 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
1032 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), 1033 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(),
1033 parent1_name); 1034 parent1_name);
1034 ASSERT_TRUE(parent.good()); 1035 ASSERT_TRUE(parent.good());
1035 parent.Put(syncable::IS_UNSYNCED, true); 1036 parent.Put(syncable::IS_UNSYNCED, true);
1036 parent.Put(syncable::IS_DIR, true); 1037 parent.Put(syncable::IS_DIR, true);
1037 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1038 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1038 parent.Put(syncable::ID, parent_id_); 1039 parent.Put(syncable::ID, parent_id_);
1039 parent.Put(syncable::BASE_VERSION, 1); 1040 parent.Put(syncable::BASE_VERSION, 1);
1040 } 1041 }
1041 1042
1042 syncable::Id parent2_id = ids_.NewLocalId(); 1043 syncable::Id parent2_id = ids_.NewLocalId();
1043 syncable::Id child_id = ids_.NewServerId(); 1044 syncable::Id child_id = ids_.NewServerId();
1044 { 1045 {
1045 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 1046 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
1046 MutableEntry parent2(&wtrans, syncable::CREATE, parent_id_, parent2_name); 1047 MutableEntry parent2(&wtrans, syncable::CREATE, parent_id_, parent2_name);
1047 ASSERT_TRUE(parent2.good()); 1048 ASSERT_TRUE(parent2.good());
1048 parent2.Put(syncable::IS_UNSYNCED, true); 1049 parent2.Put(syncable::IS_UNSYNCED, true);
1049 parent2.Put(syncable::IS_DIR, true); 1050 parent2.Put(syncable::IS_DIR, true);
1050 parent2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1051 parent2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1051 parent2.Put(syncable::ID, parent2_id); 1052 parent2.Put(syncable::ID, parent2_id);
1052 1053
1053 MutableEntry child(&wtrans, syncable::CREATE, parent2_id, child_name); 1054 MutableEntry child(&wtrans, syncable::CREATE, parent2_id, child_name);
1054 ASSERT_TRUE(child.good()); 1055 ASSERT_TRUE(child.good());
1055 child.Put(syncable::IS_UNSYNCED, true); 1056 child.Put(syncable::IS_UNSYNCED, true);
1056 child.Put(syncable::IS_DIR, true); 1057 child.Put(syncable::IS_DIR, true);
1057 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1058 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1058 child.Put(syncable::ID, child_id); 1059 child.Put(syncable::ID, child_id);
1059 child.Put(syncable::BASE_VERSION, 1); 1060 child.Put(syncable::BASE_VERSION, 1);
1060 } 1061 }
1061 1062
1062 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 1063 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
1063 EXPECT_TRUE(3 == session_->status_controller()->unsynced_handles().size()); 1064 EXPECT_TRUE(3 == session_->status_controller()->unsynced_handles().size());
1064 ASSERT_TRUE(3 == mock_server_->committed_ids().size()); 1065 ASSERT_TRUE(3 == mock_server_->committed_ids().size());
1065 // If this test starts failing, be aware other sort orders could be valid. 1066 // If this test starts failing, be aware other sort orders could be valid.
1066 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1067 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1067 EXPECT_TRUE(parent2_id == mock_server_->committed_ids()[1]); 1068 EXPECT_TRUE(parent2_id == mock_server_->committed_ids()[1]);
1068 EXPECT_TRUE(child_id == mock_server_->committed_ids()[2]); 1069 EXPECT_TRUE(child_id == mock_server_->committed_ids()[2]);
1069 { 1070 {
1070 ReadTransaction rtrans(dir, __FILE__, __LINE__); 1071 ReadTransaction rtrans(dir, FROM_HERE);
1071 // Check that things committed correctly. 1072 // Check that things committed correctly.
1072 Entry entry_1(&rtrans, syncable::GET_BY_ID, parent_id_); 1073 Entry entry_1(&rtrans, syncable::GET_BY_ID, parent_id_);
1073 EXPECT_EQ(entry_1.Get(NON_UNIQUE_NAME), parent1_name); 1074 EXPECT_EQ(entry_1.Get(NON_UNIQUE_NAME), parent1_name);
1074 // Check that parent2 is a subfolder of parent1. 1075 // Check that parent2 is a subfolder of parent1.
1075 EXPECT_EQ(1, CountEntriesWithName(&rtrans, 1076 EXPECT_EQ(1, CountEntriesWithName(&rtrans,
1076 parent_id_, 1077 parent_id_,
1077 parent2_name)); 1078 parent2_name));
1078 1079
1079 // Parent2 was a local ID and thus should have changed on commit! 1080 // Parent2 was a local ID and thus should have changed on commit!
1080 Entry pre_commit_entry_parent2(&rtrans, syncable::GET_BY_ID, parent2_id); 1081 Entry pre_commit_entry_parent2(&rtrans, syncable::GET_BY_ID, parent2_id);
(...skipping 11 matching lines...) Expand all
1092 1093
1093 TEST_F(SyncerTest, TestCommitListOrderingAndNewParentAndChild) { 1094 TEST_F(SyncerTest, TestCommitListOrderingAndNewParentAndChild) {
1094 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 1095 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
1095 ASSERT_TRUE(dir.good()); 1096 ASSERT_TRUE(dir.good());
1096 1097
1097 string parent_name = "1"; 1098 string parent_name = "1";
1098 string parent2_name = "A"; 1099 string parent2_name = "A";
1099 string child_name = "B"; 1100 string child_name = "B";
1100 1101
1101 { 1102 {
1102 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 1103 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
1103 MutableEntry parent(&wtrans, 1104 MutableEntry parent(&wtrans,
1104 syncable::CREATE, 1105 syncable::CREATE,
1105 wtrans.root_id(), 1106 wtrans.root_id(),
1106 parent_name); 1107 parent_name);
1107 ASSERT_TRUE(parent.good()); 1108 ASSERT_TRUE(parent.good());
1108 parent.Put(syncable::IS_UNSYNCED, true); 1109 parent.Put(syncable::IS_UNSYNCED, true);
1109 parent.Put(syncable::IS_DIR, true); 1110 parent.Put(syncable::IS_DIR, true);
1110 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1111 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1111 parent.Put(syncable::ID, parent_id_); 1112 parent.Put(syncable::ID, parent_id_);
1112 parent.Put(syncable::BASE_VERSION, 1); 1113 parent.Put(syncable::BASE_VERSION, 1);
1113 } 1114 }
1114 1115
1115 int64 meta_handle_a, meta_handle_b; 1116 int64 meta_handle_a, meta_handle_b;
1116 const Id parent2_local_id = ids_.NewLocalId(); 1117 const Id parent2_local_id = ids_.NewLocalId();
1117 const Id child_local_id = ids_.NewLocalId(); 1118 const Id child_local_id = ids_.NewLocalId();
1118 { 1119 {
1119 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 1120 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
1120 MutableEntry parent2(&wtrans, syncable::CREATE, parent_id_, parent2_name); 1121 MutableEntry parent2(&wtrans, syncable::CREATE, parent_id_, parent2_name);
1121 ASSERT_TRUE(parent2.good()); 1122 ASSERT_TRUE(parent2.good());
1122 parent2.Put(syncable::IS_UNSYNCED, true); 1123 parent2.Put(syncable::IS_UNSYNCED, true);
1123 parent2.Put(syncable::IS_DIR, true); 1124 parent2.Put(syncable::IS_DIR, true);
1124 parent2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1125 parent2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1125 1126
1126 parent2.Put(syncable::ID, parent2_local_id); 1127 parent2.Put(syncable::ID, parent2_local_id);
1127 meta_handle_a = parent2.Get(syncable::META_HANDLE); 1128 meta_handle_a = parent2.Get(syncable::META_HANDLE);
1128 MutableEntry child(&wtrans, syncable::CREATE, parent2_local_id, child_name); 1129 MutableEntry child(&wtrans, syncable::CREATE, parent2_local_id, child_name);
1129 ASSERT_TRUE(child.good()); 1130 ASSERT_TRUE(child.good());
1130 child.Put(syncable::IS_UNSYNCED, true); 1131 child.Put(syncable::IS_UNSYNCED, true);
1131 child.Put(syncable::IS_DIR, true); 1132 child.Put(syncable::IS_DIR, true);
1132 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1133 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1133 child.Put(syncable::ID, child_local_id); 1134 child.Put(syncable::ID, child_local_id);
1134 meta_handle_b = child.Get(syncable::META_HANDLE); 1135 meta_handle_b = child.Get(syncable::META_HANDLE);
1135 } 1136 }
1136 1137
1137 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 1138 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
1138 EXPECT_TRUE(3 == session_->status_controller()->unsynced_handles().size()); 1139 EXPECT_TRUE(3 == session_->status_controller()->unsynced_handles().size());
1139 ASSERT_TRUE(3 == mock_server_->committed_ids().size()); 1140 ASSERT_TRUE(3 == mock_server_->committed_ids().size());
1140 // If this test starts failing, be aware other sort orders could be valid. 1141 // If this test starts failing, be aware other sort orders could be valid.
1141 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1142 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1142 EXPECT_TRUE(parent2_local_id == mock_server_->committed_ids()[1]); 1143 EXPECT_TRUE(parent2_local_id == mock_server_->committed_ids()[1]);
1143 EXPECT_TRUE(child_local_id == mock_server_->committed_ids()[2]); 1144 EXPECT_TRUE(child_local_id == mock_server_->committed_ids()[2]);
1144 { 1145 {
1145 ReadTransaction rtrans(dir, __FILE__, __LINE__); 1146 ReadTransaction rtrans(dir, FROM_HERE);
1146 1147
1147 Entry parent(&rtrans, syncable::GET_BY_ID, 1148 Entry parent(&rtrans, syncable::GET_BY_ID,
1148 GetOnlyEntryWithName(&rtrans, rtrans.root_id(), parent_name)); 1149 GetOnlyEntryWithName(&rtrans, rtrans.root_id(), parent_name));
1149 ASSERT_TRUE(parent.good()); 1150 ASSERT_TRUE(parent.good());
1150 EXPECT_TRUE(parent.Get(syncable::ID).ServerKnows()); 1151 EXPECT_TRUE(parent.Get(syncable::ID).ServerKnows());
1151 1152
1152 Entry parent2(&rtrans, syncable::GET_BY_ID, 1153 Entry parent2(&rtrans, syncable::GET_BY_ID,
1153 GetOnlyEntryWithName(&rtrans, parent.Get(ID), parent2_name)); 1154 GetOnlyEntryWithName(&rtrans, parent.Get(ID), parent2_name));
1154 ASSERT_TRUE(parent2.good()); 1155 ASSERT_TRUE(parent2.good());
1155 EXPECT_TRUE(parent2.Get(syncable::ID).ServerKnows()); 1156 EXPECT_TRUE(parent2.Get(syncable::ID).ServerKnows());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 ASSERT_TRUE(dir.good()); 1199 ASSERT_TRUE(dir.good());
1199 string id = "some_id"; 1200 string id = "some_id";
1200 string parent_id = "0"; 1201 string parent_id = "0";
1201 string name = "in_root"; 1202 string name = "in_root";
1202 int64 version = 10; 1203 int64 version = 10;
1203 int64 timestamp = 10; 1204 int64 timestamp = 10;
1204 mock_server_->AddUpdateDirectory(id, parent_id, name, version, timestamp); 1205 mock_server_->AddUpdateDirectory(id, parent_id, name, version, timestamp);
1205 1206
1206 SyncShareAsDelegate(); 1207 SyncShareAsDelegate();
1207 { 1208 {
1208 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 1209 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
1209 Entry entry(&trans, GET_BY_ID, 1210 Entry entry(&trans, GET_BY_ID,
1210 syncable::Id::CreateFromServerId("some_id")); 1211 syncable::Id::CreateFromServerId("some_id"));
1211 ASSERT_TRUE(entry.good()); 1212 ASSERT_TRUE(entry.good());
1212 EXPECT_TRUE(entry.Get(IS_DIR)); 1213 EXPECT_TRUE(entry.Get(IS_DIR));
1213 EXPECT_TRUE(entry.Get(SERVER_VERSION) == version); 1214 EXPECT_TRUE(entry.Get(SERVER_VERSION) == version);
1214 EXPECT_TRUE(entry.Get(BASE_VERSION) == version); 1215 EXPECT_TRUE(entry.Get(BASE_VERSION) == version);
1215 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE)); 1216 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE));
1216 EXPECT_FALSE(entry.Get(IS_UNSYNCED)); 1217 EXPECT_FALSE(entry.Get(IS_UNSYNCED));
1217 EXPECT_FALSE(entry.Get(SERVER_IS_DEL)); 1218 EXPECT_FALSE(entry.Get(SERVER_IS_DEL));
1218 EXPECT_FALSE(entry.Get(IS_DEL)); 1219 EXPECT_FALSE(entry.Get(IS_DEL));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 1258 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
1258 // The three items with an unresolved parent should be unapplied (3, 9, 100). 1259 // The three items with an unresolved parent should be unapplied (3, 9, 100).
1259 // The name clash should also still be in conflict. 1260 // The name clash should also still be in conflict.
1260 EXPECT_EQ(3, status->TotalNumConflictingItems()); 1261 EXPECT_EQ(3, status->TotalNumConflictingItems());
1261 { 1262 {
1262 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); 1263 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE);
1263 EXPECT_EQ(3, status->conflict_progress().ConflictingItemsSize()); 1264 EXPECT_EQ(3, status->conflict_progress().ConflictingItemsSize());
1264 } 1265 }
1265 1266
1266 { 1267 {
1267 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 1268 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
1268 // Even though it has the same name, it should work. 1269 // Even though it has the same name, it should work.
1269 Entry name_clash(&trans, GET_BY_ID, ids_.FromNumber(2)); 1270 Entry name_clash(&trans, GET_BY_ID, ids_.FromNumber(2));
1270 ASSERT_TRUE(name_clash.good()); 1271 ASSERT_TRUE(name_clash.good());
1271 EXPECT_FALSE(name_clash.Get(IS_UNAPPLIED_UPDATE)) 1272 EXPECT_FALSE(name_clash.Get(IS_UNAPPLIED_UPDATE))
1272 << "Duplicate name SHOULD be OK."; 1273 << "Duplicate name SHOULD be OK.";
1273 1274
1274 Entry bad_parent(&trans, GET_BY_ID, ids_.FromNumber(3)); 1275 Entry bad_parent(&trans, GET_BY_ID, ids_.FromNumber(3));
1275 ASSERT_TRUE(bad_parent.good()); 1276 ASSERT_TRUE(bad_parent.good());
1276 EXPECT_TRUE(bad_parent.Get(IS_UNAPPLIED_UPDATE)) 1277 EXPECT_TRUE(bad_parent.Get(IS_UNAPPLIED_UPDATE))
1277 << "child of unknown parent should be in conflict"; 1278 << "child of unknown parent should be in conflict";
(...skipping 16 matching lines...) Expand all
1294 mock_server_->AddUpdateDirectory(5, 6, "circular3", 20, 20); 1295 mock_server_->AddUpdateDirectory(5, 6, "circular3", 20, 20);
1295 1296
1296 // Flip the is_dir bit: should fail verify & be dropped. 1297 // Flip the is_dir bit: should fail verify & be dropped.
1297 mock_server_->AddUpdateBookmark(10, 0, "dir_to_bookmark", 20, 20); 1298 mock_server_->AddUpdateBookmark(10, 0, "dir_to_bookmark", 20, 20);
1298 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 1299 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
1299 1300
1300 // Version number older than last known: should fail verify & be dropped. 1301 // Version number older than last known: should fail verify & be dropped.
1301 mock_server_->AddUpdateDirectory(4, 0, "old_version", 10, 10); 1302 mock_server_->AddUpdateDirectory(4, 0, "old_version", 10, 10);
1302 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 1303 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
1303 { 1304 {
1304 ReadTransaction trans(dir, __FILE__, __LINE__); 1305 ReadTransaction trans(dir, FROM_HERE);
1305 1306
1306 Entry still_a_dir(&trans, GET_BY_ID, ids_.FromNumber(10)); 1307 Entry still_a_dir(&trans, GET_BY_ID, ids_.FromNumber(10));
1307 ASSERT_TRUE(still_a_dir.good()); 1308 ASSERT_TRUE(still_a_dir.good());
1308 EXPECT_FALSE(still_a_dir.Get(IS_UNAPPLIED_UPDATE)); 1309 EXPECT_FALSE(still_a_dir.Get(IS_UNAPPLIED_UPDATE));
1309 EXPECT_TRUE(10 == still_a_dir.Get(BASE_VERSION)); 1310 EXPECT_TRUE(10 == still_a_dir.Get(BASE_VERSION));
1310 EXPECT_TRUE(10 == still_a_dir.Get(SERVER_VERSION)); 1311 EXPECT_TRUE(10 == still_a_dir.Get(SERVER_VERSION));
1311 EXPECT_TRUE(still_a_dir.Get(IS_DIR)); 1312 EXPECT_TRUE(still_a_dir.Get(IS_DIR));
1312 1313
1313 Entry rename(&trans, GET_BY_ID, ids_.FromNumber(1)); 1314 Entry rename(&trans, GET_BY_ID, ids_.FromNumber(1));
1314 ASSERT_TRUE(rename.good()); 1315 ASSERT_TRUE(rename.good());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 } 1359 }
1359 1360
1360 TEST_F(SyncerTest, CommitTimeRename) { 1361 TEST_F(SyncerTest, CommitTimeRename) {
1361 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 1362 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
1362 ASSERT_TRUE(dir.good()); 1363 ASSERT_TRUE(dir.good());
1363 int64 metahandle_folder; 1364 int64 metahandle_folder;
1364 int64 metahandle_new_entry; 1365 int64 metahandle_new_entry;
1365 1366
1366 // Create a folder and an entry. 1367 // Create a folder and an entry.
1367 { 1368 {
1368 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 1369 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
1369 MutableEntry parent(&trans, CREATE, root_id_, "Folder"); 1370 MutableEntry parent(&trans, CREATE, root_id_, "Folder");
1370 ASSERT_TRUE(parent.good()); 1371 ASSERT_TRUE(parent.good());
1371 parent.Put(IS_DIR, true); 1372 parent.Put(IS_DIR, true);
1372 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1373 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1373 parent.Put(IS_UNSYNCED, true); 1374 parent.Put(IS_UNSYNCED, true);
1374 metahandle_folder = parent.Get(META_HANDLE); 1375 metahandle_folder = parent.Get(META_HANDLE);
1375 1376
1376 MutableEntry entry(&trans, CREATE, parent.Get(ID), "new_entry"); 1377 MutableEntry entry(&trans, CREATE, parent.Get(ID), "new_entry");
1377 ASSERT_TRUE(entry.good()); 1378 ASSERT_TRUE(entry.good());
1378 metahandle_new_entry = entry.Get(META_HANDLE); 1379 metahandle_new_entry = entry.Get(META_HANDLE);
1379 WriteTestDataToEntry(&trans, &entry); 1380 WriteTestDataToEntry(&trans, &entry);
1380 } 1381 }
1381 1382
1382 // Mix in a directory creation too for later. 1383 // Mix in a directory creation too for later.
1383 mock_server_->AddUpdateDirectory(2, 0, "dir_in_root", 10, 10); 1384 mock_server_->AddUpdateDirectory(2, 0, "dir_in_root", 10, 10);
1384 mock_server_->SetCommitTimeRename("renamed_"); 1385 mock_server_->SetCommitTimeRename("renamed_");
1385 SyncShareAsDelegate(); 1386 SyncShareAsDelegate();
1386 1387
1387 // Verify it was correctly renamed. 1388 // Verify it was correctly renamed.
1388 { 1389 {
1389 ReadTransaction trans(dir, __FILE__, __LINE__); 1390 ReadTransaction trans(dir, FROM_HERE);
1390 Entry entry_folder(&trans, GET_BY_HANDLE, metahandle_folder); 1391 Entry entry_folder(&trans, GET_BY_HANDLE, metahandle_folder);
1391 ASSERT_TRUE(entry_folder.good()); 1392 ASSERT_TRUE(entry_folder.good());
1392 EXPECT_EQ("renamed_Folder", entry_folder.Get(NON_UNIQUE_NAME)); 1393 EXPECT_EQ("renamed_Folder", entry_folder.Get(NON_UNIQUE_NAME));
1393 1394
1394 Entry entry_new(&trans, GET_BY_HANDLE, metahandle_new_entry); 1395 Entry entry_new(&trans, GET_BY_HANDLE, metahandle_new_entry);
1395 ASSERT_TRUE(entry_new.good()); 1396 ASSERT_TRUE(entry_new.good());
1396 EXPECT_EQ(entry_folder.Get(ID), entry_new.Get(PARENT_ID)); 1397 EXPECT_EQ(entry_folder.Get(ID), entry_new.Get(PARENT_ID));
1397 EXPECT_EQ("renamed_new_entry", entry_new.Get(NON_UNIQUE_NAME)); 1398 EXPECT_EQ("renamed_new_entry", entry_new.Get(NON_UNIQUE_NAME));
1398 1399
1399 // And that the unrelated directory creation worked without a rename. 1400 // And that the unrelated directory creation worked without a rename.
1400 Entry new_dir(&trans, GET_BY_ID, ids_.FromNumber(2)); 1401 Entry new_dir(&trans, GET_BY_ID, ids_.FromNumber(2));
1401 EXPECT_TRUE(new_dir.good()); 1402 EXPECT_TRUE(new_dir.good());
1402 EXPECT_EQ("dir_in_root", new_dir.Get(NON_UNIQUE_NAME)); 1403 EXPECT_EQ("dir_in_root", new_dir.Get(NON_UNIQUE_NAME));
1403 } 1404 }
1404 } 1405 }
1405 1406
1406 1407
1407 TEST_F(SyncerTest, CommitTimeRenameI18N) { 1408 TEST_F(SyncerTest, CommitTimeRenameI18N) {
1408 // This is utf-8 for the diacritized Internationalization. 1409 // This is utf-8 for the diacritized Internationalization.
1409 const char* i18nString = "\xc3\x8e\xc3\xb1\x74\xc3\xa9\x72\xc3\xb1" 1410 const char* i18nString = "\xc3\x8e\xc3\xb1\x74\xc3\xa9\x72\xc3\xb1"
1410 "\xc3\xa5\x74\xc3\xae\xc3\xb6\xc3\xb1\xc3\xa5\x6c\xc3\xae" 1411 "\xc3\xa5\x74\xc3\xae\xc3\xb6\xc3\xb1\xc3\xa5\x6c\xc3\xae"
1411 "\xc2\x9e\xc3\xa5\x74\xc3\xae\xc3\xb6\xc3\xb1"; 1412 "\xc2\x9e\xc3\xa5\x74\xc3\xae\xc3\xb6\xc3\xb1";
1412 1413
1413 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 1414 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
1414 ASSERT_TRUE(dir.good()); 1415 ASSERT_TRUE(dir.good());
1415 int64 metahandle; 1416 int64 metahandle;
1416 // Create a folder, expect a commit time rename. 1417 // Create a folder, expect a commit time rename.
1417 { 1418 {
1418 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 1419 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
1419 MutableEntry parent(&trans, CREATE, root_id_, "Folder"); 1420 MutableEntry parent(&trans, CREATE, root_id_, "Folder");
1420 ASSERT_TRUE(parent.good()); 1421 ASSERT_TRUE(parent.good());
1421 parent.Put(IS_DIR, true); 1422 parent.Put(IS_DIR, true);
1422 parent.Put(SPECIFICS, DefaultBookmarkSpecifics()); 1423 parent.Put(SPECIFICS, DefaultBookmarkSpecifics());
1423 parent.Put(IS_UNSYNCED, true); 1424 parent.Put(IS_UNSYNCED, true);
1424 metahandle = parent.Get(META_HANDLE); 1425 metahandle = parent.Get(META_HANDLE);
1425 } 1426 }
1426 1427
1427 mock_server_->SetCommitTimeRename(i18nString); 1428 mock_server_->SetCommitTimeRename(i18nString);
1428 SyncShareAsDelegate(); 1429 SyncShareAsDelegate();
1429 1430
1430 // Verify it was correctly renamed. 1431 // Verify it was correctly renamed.
1431 { 1432 {
1432 ReadTransaction trans(dir, __FILE__, __LINE__); 1433 ReadTransaction trans(dir, FROM_HERE);
1433 string expected_folder_name(i18nString); 1434 string expected_folder_name(i18nString);
1434 expected_folder_name.append("Folder"); 1435 expected_folder_name.append("Folder");
1435 1436
1436 1437
1437 Entry entry_folder(&trans, GET_BY_HANDLE, metahandle); 1438 Entry entry_folder(&trans, GET_BY_HANDLE, metahandle);
1438 ASSERT_TRUE(entry_folder.good()); 1439 ASSERT_TRUE(entry_folder.good());
1439 EXPECT_EQ(expected_folder_name, entry_folder.Get(NON_UNIQUE_NAME)); 1440 EXPECT_EQ(expected_folder_name, entry_folder.Get(NON_UNIQUE_NAME));
1440 } 1441 }
1441 } 1442 }
1442 1443
1443 // A commit with a lost response produces an update that has to be reunited with 1444 // A commit with a lost response produces an update that has to be reunited with
1444 // its parent. 1445 // its parent.
1445 TEST_F(SyncerTest, CommitReuniteUpdateAdjustsChildren) { 1446 TEST_F(SyncerTest, CommitReuniteUpdateAdjustsChildren) {
1446 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 1447 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
1447 ASSERT_TRUE(dir.good()); 1448 ASSERT_TRUE(dir.good());
1448 1449
1449 // Create a folder in the root. 1450 // Create a folder in the root.
1450 int64 metahandle_folder; 1451 int64 metahandle_folder;
1451 { 1452 {
1452 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 1453 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
1453 MutableEntry entry(&trans, CREATE, trans.root_id(), "new_folder"); 1454 MutableEntry entry(&trans, CREATE, trans.root_id(), "new_folder");
1454 ASSERT_TRUE(entry.good()); 1455 ASSERT_TRUE(entry.good());
1455 entry.Put(IS_DIR, true); 1456 entry.Put(IS_DIR, true);
1456 entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); 1457 entry.Put(SPECIFICS, DefaultBookmarkSpecifics());
1457 entry.Put(IS_UNSYNCED, true); 1458 entry.Put(IS_UNSYNCED, true);
1458 metahandle_folder = entry.Get(META_HANDLE); 1459 metahandle_folder = entry.Get(META_HANDLE);
1459 } 1460 }
1460 1461
1461 // Verify it and pull the ID out of the folder. 1462 // Verify it and pull the ID out of the folder.
1462 syncable::Id folder_id; 1463 syncable::Id folder_id;
1463 int64 metahandle_entry; 1464 int64 metahandle_entry;
1464 { 1465 {
1465 ReadTransaction trans(dir, __FILE__, __LINE__); 1466 ReadTransaction trans(dir, FROM_HERE);
1466 Entry entry(&trans, GET_BY_HANDLE, metahandle_folder); 1467 Entry entry(&trans, GET_BY_HANDLE, metahandle_folder);
1467 ASSERT_TRUE(entry.good()); 1468 ASSERT_TRUE(entry.good());
1468 folder_id = entry.Get(ID); 1469 folder_id = entry.Get(ID);
1469 ASSERT_TRUE(!folder_id.ServerKnows()); 1470 ASSERT_TRUE(!folder_id.ServerKnows());
1470 } 1471 }
1471 1472
1472 // Create an entry in the newly created folder. 1473 // Create an entry in the newly created folder.
1473 { 1474 {
1474 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 1475 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
1475 MutableEntry entry(&trans, CREATE, folder_id, "new_entry"); 1476 MutableEntry entry(&trans, CREATE, folder_id, "new_entry");
1476 ASSERT_TRUE(entry.good()); 1477 ASSERT_TRUE(entry.good());
1477 metahandle_entry = entry.Get(META_HANDLE); 1478 metahandle_entry = entry.Get(META_HANDLE);
1478 WriteTestDataToEntry(&trans, &entry); 1479 WriteTestDataToEntry(&trans, &entry);
1479 } 1480 }
1480 1481
1481 // Verify it and pull the ID out of the entry. 1482 // Verify it and pull the ID out of the entry.
1482 syncable::Id entry_id; 1483 syncable::Id entry_id;
1483 { 1484 {
1484 ReadTransaction trans(dir, __FILE__, __LINE__); 1485 ReadTransaction trans(dir, FROM_HERE);
1485 Entry entry(&trans, syncable::GET_BY_HANDLE, metahandle_entry); 1486 Entry entry(&trans, syncable::GET_BY_HANDLE, metahandle_entry);
1486 ASSERT_TRUE(entry.good()); 1487 ASSERT_TRUE(entry.good());
1487 EXPECT_EQ(folder_id, entry.Get(PARENT_ID)); 1488 EXPECT_EQ(folder_id, entry.Get(PARENT_ID));
1488 EXPECT_EQ("new_entry", entry.Get(NON_UNIQUE_NAME)); 1489 EXPECT_EQ("new_entry", entry.Get(NON_UNIQUE_NAME));
1489 entry_id = entry.Get(ID); 1490 entry_id = entry.Get(ID);
1490 EXPECT_TRUE(!entry_id.ServerKnows()); 1491 EXPECT_TRUE(!entry_id.ServerKnows());
1491 VerifyTestDataInEntry(&trans, &entry); 1492 VerifyTestDataInEntry(&trans, &entry);
1492 } 1493 }
1493 1494
1494 // Now, to emulate a commit response failure, we just don't commit it. 1495 // Now, to emulate a commit response failure, we just don't commit it.
1495 int64 new_version = 150; // any larger value. 1496 int64 new_version = 150; // any larger value.
1496 int64 timestamp = 20; // arbitrary value. 1497 int64 timestamp = 20; // arbitrary value.
1497 syncable::Id new_folder_id = 1498 syncable::Id new_folder_id =
1498 syncable::Id::CreateFromServerId("folder_server_id"); 1499 syncable::Id::CreateFromServerId("folder_server_id");
1499 1500
1500 // The following update should cause the folder to both apply the update, as 1501 // The following update should cause the folder to both apply the update, as
1501 // well as reassociate the id. 1502 // well as reassociate the id.
1502 mock_server_->AddUpdateDirectory(new_folder_id, root_id_, 1503 mock_server_->AddUpdateDirectory(new_folder_id, root_id_,
1503 "new_folder", new_version, timestamp); 1504 "new_folder", new_version, timestamp);
1504 mock_server_->SetLastUpdateOriginatorFields( 1505 mock_server_->SetLastUpdateOriginatorFields(
1505 dir->cache_guid(), folder_id.GetServerId()); 1506 dir->cache_guid(), folder_id.GetServerId());
1506 1507
1507 // We don't want it accidentally committed, just the update applied. 1508 // We don't want it accidentally committed, just the update applied.
1508 mock_server_->set_conflict_all_commits(true); 1509 mock_server_->set_conflict_all_commits(true);
1509 1510
1510 // Alright! Apply that update! 1511 // Alright! Apply that update!
1511 SyncShareAsDelegate(); 1512 SyncShareAsDelegate();
1512 { 1513 {
1513 // The folder's ID should have been updated. 1514 // The folder's ID should have been updated.
1514 ReadTransaction trans(dir, __FILE__, __LINE__); 1515 ReadTransaction trans(dir, FROM_HERE);
1515 Entry folder(&trans, GET_BY_HANDLE, metahandle_folder); 1516 Entry folder(&trans, GET_BY_HANDLE, metahandle_folder);
1516 ASSERT_TRUE(folder.good()); 1517 ASSERT_TRUE(folder.good());
1517 EXPECT_EQ("new_folder", folder.Get(NON_UNIQUE_NAME)); 1518 EXPECT_EQ("new_folder", folder.Get(NON_UNIQUE_NAME));
1518 EXPECT_TRUE(new_version == folder.Get(BASE_VERSION)); 1519 EXPECT_TRUE(new_version == folder.Get(BASE_VERSION));
1519 EXPECT_TRUE(new_folder_id == folder.Get(ID)); 1520 EXPECT_TRUE(new_folder_id == folder.Get(ID));
1520 EXPECT_TRUE(folder.Get(ID).ServerKnows()); 1521 EXPECT_TRUE(folder.Get(ID).ServerKnows());
1521 EXPECT_EQ(trans.root_id(), folder.Get(PARENT_ID)); 1522 EXPECT_EQ(trans.root_id(), folder.Get(PARENT_ID));
1522 1523
1523 // Since it was updated, the old folder should not exist. 1524 // Since it was updated, the old folder should not exist.
1524 Entry old_dead_folder(&trans, GET_BY_ID, folder_id); 1525 Entry old_dead_folder(&trans, GET_BY_ID, folder_id);
(...skipping 11 matching lines...) Expand all
1536 1537
1537 // A commit with a lost response produces an update that has to be reunited with 1538 // A commit with a lost response produces an update that has to be reunited with
1538 // its parent. 1539 // its parent.
1539 TEST_F(SyncerTest, CommitReuniteUpdate) { 1540 TEST_F(SyncerTest, CommitReuniteUpdate) {
1540 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 1541 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
1541 ASSERT_TRUE(dir.good()); 1542 ASSERT_TRUE(dir.good());
1542 1543
1543 // Create an entry in the root. 1544 // Create an entry in the root.
1544 int64 entry_metahandle; 1545 int64 entry_metahandle;
1545 { 1546 {
1546 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 1547 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
1547 MutableEntry entry(&trans, CREATE, trans.root_id(), "new_entry"); 1548 MutableEntry entry(&trans, CREATE, trans.root_id(), "new_entry");
1548 ASSERT_TRUE(entry.good()); 1549 ASSERT_TRUE(entry.good());
1549 entry_metahandle = entry.Get(META_HANDLE); 1550 entry_metahandle = entry.Get(META_HANDLE);
1550 WriteTestDataToEntry(&trans, &entry); 1551 WriteTestDataToEntry(&trans, &entry);
1551 } 1552 }
1552 1553
1553 // Verify it and pull the ID out. 1554 // Verify it and pull the ID out.
1554 syncable::Id entry_id; 1555 syncable::Id entry_id;
1555 { 1556 {
1556 ReadTransaction trans(dir, __FILE__, __LINE__); 1557 ReadTransaction trans(dir, FROM_HERE);
1557 1558
1558 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle); 1559 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle);
1559 ASSERT_TRUE(entry.good()); 1560 ASSERT_TRUE(entry.good());
1560 entry_id = entry.Get(ID); 1561 entry_id = entry.Get(ID);
1561 EXPECT_TRUE(!entry_id.ServerKnows()); 1562 EXPECT_TRUE(!entry_id.ServerKnows());
1562 VerifyTestDataInEntry(&trans, &entry); 1563 VerifyTestDataInEntry(&trans, &entry);
1563 } 1564 }
1564 1565
1565 // Now, to emulate a commit response failure, we just don't commit it. 1566 // Now, to emulate a commit response failure, we just don't commit it.
1566 int64 new_version = 150; // any larger value. 1567 int64 new_version = 150; // any larger value.
1567 int64 timestamp = 20; // arbitrary value. 1568 int64 timestamp = 20; // arbitrary value.
1568 syncable::Id new_entry_id = syncable::Id::CreateFromServerId("server_id"); 1569 syncable::Id new_entry_id = syncable::Id::CreateFromServerId("server_id");
1569 1570
1570 // Generate an update from the server with a relevant ID reassignment. 1571 // Generate an update from the server with a relevant ID reassignment.
1571 mock_server_->AddUpdateBookmark(new_entry_id, root_id_, 1572 mock_server_->AddUpdateBookmark(new_entry_id, root_id_,
1572 "new_entry", new_version, timestamp); 1573 "new_entry", new_version, timestamp);
1573 mock_server_->SetLastUpdateOriginatorFields( 1574 mock_server_->SetLastUpdateOriginatorFields(
1574 dir->cache_guid(), entry_id.GetServerId()); 1575 dir->cache_guid(), entry_id.GetServerId());
1575 1576
1576 // We don't want it accidentally committed, just the update applied. 1577 // We don't want it accidentally committed, just the update applied.
1577 mock_server_->set_conflict_all_commits(true); 1578 mock_server_->set_conflict_all_commits(true);
1578 1579
1579 // Alright! Apply that update! 1580 // Alright! Apply that update!
1580 SyncShareAsDelegate(); 1581 SyncShareAsDelegate();
1581 { 1582 {
1582 ReadTransaction trans(dir, __FILE__, __LINE__); 1583 ReadTransaction trans(dir, FROM_HERE);
1583 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle); 1584 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle);
1584 ASSERT_TRUE(entry.good()); 1585 ASSERT_TRUE(entry.good());
1585 EXPECT_TRUE(new_version == entry.Get(BASE_VERSION)); 1586 EXPECT_TRUE(new_version == entry.Get(BASE_VERSION));
1586 EXPECT_TRUE(new_entry_id == entry.Get(ID)); 1587 EXPECT_TRUE(new_entry_id == entry.Get(ID));
1587 EXPECT_EQ("new_entry", entry.Get(NON_UNIQUE_NAME)); 1588 EXPECT_EQ("new_entry", entry.Get(NON_UNIQUE_NAME));
1588 } 1589 }
1589 } 1590 }
1590 1591
1591 // A commit with a lost response must work even if the local entry was deleted 1592 // A commit with a lost response must work even if the local entry was deleted
1592 // before the update is applied. We should not duplicate the local entry in 1593 // before the update is applied. We should not duplicate the local entry in
1593 // this case, but just create another one alongside. We may wish to examine 1594 // this case, but just create another one alongside. We may wish to examine
1594 // this behavior in the future as it can create hanging uploads that never 1595 // this behavior in the future as it can create hanging uploads that never
1595 // finish, that must be cleaned up on the server side after some time. 1596 // finish, that must be cleaned up on the server side after some time.
1596 TEST_F(SyncerTest, CommitReuniteUpdateDoesNotChokeOnDeletedLocalEntry) { 1597 TEST_F(SyncerTest, CommitReuniteUpdateDoesNotChokeOnDeletedLocalEntry) {
1597 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 1598 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
1598 ASSERT_TRUE(dir.good()); 1599 ASSERT_TRUE(dir.good());
1599 1600
1600 // Create a entry in the root. 1601 // Create a entry in the root.
1601 int64 entry_metahandle; 1602 int64 entry_metahandle;
1602 { 1603 {
1603 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 1604 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
1604 MutableEntry entry(&trans, CREATE, trans.root_id(), "new_entry"); 1605 MutableEntry entry(&trans, CREATE, trans.root_id(), "new_entry");
1605 ASSERT_TRUE(entry.good()); 1606 ASSERT_TRUE(entry.good());
1606 entry_metahandle = entry.Get(META_HANDLE); 1607 entry_metahandle = entry.Get(META_HANDLE);
1607 WriteTestDataToEntry(&trans, &entry); 1608 WriteTestDataToEntry(&trans, &entry);
1608 } 1609 }
1609 // Verify it and pull the ID out. 1610 // Verify it and pull the ID out.
1610 syncable::Id entry_id; 1611 syncable::Id entry_id;
1611 { 1612 {
1612 ReadTransaction trans(dir, __FILE__, __LINE__); 1613 ReadTransaction trans(dir, FROM_HERE);
1613 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle); 1614 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle);
1614 ASSERT_TRUE(entry.good()); 1615 ASSERT_TRUE(entry.good());
1615 entry_id = entry.Get(ID); 1616 entry_id = entry.Get(ID);
1616 EXPECT_TRUE(!entry_id.ServerKnows()); 1617 EXPECT_TRUE(!entry_id.ServerKnows());
1617 VerifyTestDataInEntry(&trans, &entry); 1618 VerifyTestDataInEntry(&trans, &entry);
1618 } 1619 }
1619 1620
1620 // Now, to emulate a commit response failure, we just don't commit it. 1621 // Now, to emulate a commit response failure, we just don't commit it.
1621 int64 new_version = 150; // any larger value. 1622 int64 new_version = 150; // any larger value.
1622 int64 timestamp = 20; // arbitrary value. 1623 int64 timestamp = 20; // arbitrary value.
1623 syncable::Id new_entry_id = syncable::Id::CreateFromServerId("server_id"); 1624 syncable::Id new_entry_id = syncable::Id::CreateFromServerId("server_id");
1624 1625
1625 // Generate an update from the server with a relevant ID reassignment. 1626 // Generate an update from the server with a relevant ID reassignment.
1626 mock_server_->AddUpdateBookmark(new_entry_id, root_id_, 1627 mock_server_->AddUpdateBookmark(new_entry_id, root_id_,
1627 "new_entry", new_version, timestamp); 1628 "new_entry", new_version, timestamp);
1628 mock_server_->SetLastUpdateOriginatorFields( 1629 mock_server_->SetLastUpdateOriginatorFields(
1629 dir->cache_guid(), 1630 dir->cache_guid(),
1630 entry_id.GetServerId()); 1631 entry_id.GetServerId());
1631 1632
1632 // We don't want it accidentally committed, just the update applied. 1633 // We don't want it accidentally committed, just the update applied.
1633 mock_server_->set_conflict_all_commits(true); 1634 mock_server_->set_conflict_all_commits(true);
1634 1635
1635 // Purposefully delete the entry now before the update application finishes. 1636 // Purposefully delete the entry now before the update application finishes.
1636 { 1637 {
1637 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 1638 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
1638 Id new_entry_id = GetOnlyEntryWithName( 1639 Id new_entry_id = GetOnlyEntryWithName(
1639 &trans, trans.root_id(), "new_entry"); 1640 &trans, trans.root_id(), "new_entry");
1640 MutableEntry entry(&trans, GET_BY_ID, new_entry_id); 1641 MutableEntry entry(&trans, GET_BY_ID, new_entry_id);
1641 ASSERT_TRUE(entry.good()); 1642 ASSERT_TRUE(entry.good());
1642 entry.Put(syncable::IS_DEL, true); 1643 entry.Put(syncable::IS_DEL, true);
1643 } 1644 }
1644 1645
1645 // Just don't CHECK fail in sync, have the update split. 1646 // Just don't CHECK fail in sync, have the update split.
1646 SyncShareAsDelegate(); 1647 SyncShareAsDelegate();
1647 { 1648 {
1648 ReadTransaction trans(dir, __FILE__, __LINE__); 1649 ReadTransaction trans(dir, FROM_HERE);
1649 Id new_entry_id = GetOnlyEntryWithName( 1650 Id new_entry_id = GetOnlyEntryWithName(
1650 &trans, trans.root_id(), "new_entry"); 1651 &trans, trans.root_id(), "new_entry");
1651 Entry entry(&trans, GET_BY_ID, new_entry_id); 1652 Entry entry(&trans, GET_BY_ID, new_entry_id);
1652 ASSERT_TRUE(entry.good()); 1653 ASSERT_TRUE(entry.good());
1653 EXPECT_FALSE(entry.Get(IS_DEL)); 1654 EXPECT_FALSE(entry.Get(IS_DEL));
1654 1655
1655 Entry old_entry(&trans, GET_BY_ID, entry_id); 1656 Entry old_entry(&trans, GET_BY_ID, entry_id);
1656 ASSERT_TRUE(old_entry.good()); 1657 ASSERT_TRUE(old_entry.good());
1657 EXPECT_TRUE(old_entry.Get(IS_DEL)); 1658 EXPECT_TRUE(old_entry.Get(IS_DEL));
1658 } 1659 }
1659 } 1660 }
1660 1661
1661 // TODO(chron): Add more unsanitized name tests. 1662 // TODO(chron): Add more unsanitized name tests.
1662 TEST_F(SyncerTest, ConflictMatchingEntryHandlesUnsanitizedNames) { 1663 TEST_F(SyncerTest, ConflictMatchingEntryHandlesUnsanitizedNames) {
1663 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 1664 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
1664 CHECK(dir.good()); 1665 CHECK(dir.good());
1665 mock_server_->AddUpdateDirectory(1, 0, "A/A", 10, 10); 1666 mock_server_->AddUpdateDirectory(1, 0, "A/A", 10, 10);
1666 mock_server_->AddUpdateDirectory(2, 0, "B/B", 10, 10); 1667 mock_server_->AddUpdateDirectory(2, 0, "B/B", 10, 10);
1667 mock_server_->set_conflict_all_commits(true); 1668 mock_server_->set_conflict_all_commits(true);
1668 SyncShareAsDelegate(); 1669 SyncShareAsDelegate();
1669 { 1670 {
1670 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 1671 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
1671 1672
1672 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 1673 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
1673 ASSERT_TRUE(A.good()); 1674 ASSERT_TRUE(A.good());
1674 A.Put(IS_UNSYNCED, true); 1675 A.Put(IS_UNSYNCED, true);
1675 A.Put(IS_UNAPPLIED_UPDATE, true); 1676 A.Put(IS_UNAPPLIED_UPDATE, true);
1676 A.Put(SERVER_VERSION, 20); 1677 A.Put(SERVER_VERSION, 20);
1677 1678
1678 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 1679 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
1679 ASSERT_TRUE(B.good()); 1680 ASSERT_TRUE(B.good());
1680 B.Put(IS_UNAPPLIED_UPDATE, true); 1681 B.Put(IS_UNAPPLIED_UPDATE, true);
1681 B.Put(SERVER_VERSION, 20); 1682 B.Put(SERVER_VERSION, 20);
1682 } 1683 }
1683 LoopSyncShare(); 1684 LoopSyncShare();
1684 saw_syncer_event_ = false; 1685 saw_syncer_event_ = false;
1685 mock_server_->set_conflict_all_commits(false); 1686 mock_server_->set_conflict_all_commits(false);
1686 1687
1687 { 1688 {
1688 ReadTransaction trans(dir, __FILE__, __LINE__); 1689 ReadTransaction trans(dir, FROM_HERE);
1689 1690
1690 Entry A(&trans, GET_BY_ID, ids_.FromNumber(1)); 1691 Entry A(&trans, GET_BY_ID, ids_.FromNumber(1));
1691 ASSERT_TRUE(A.good()); 1692 ASSERT_TRUE(A.good());
1692 EXPECT_TRUE(A.Get(IS_UNSYNCED) == false); 1693 EXPECT_TRUE(A.Get(IS_UNSYNCED) == false);
1693 EXPECT_TRUE(A.Get(IS_UNAPPLIED_UPDATE) == false); 1694 EXPECT_TRUE(A.Get(IS_UNAPPLIED_UPDATE) == false);
1694 EXPECT_TRUE(A.Get(SERVER_VERSION) == 20); 1695 EXPECT_TRUE(A.Get(SERVER_VERSION) == 20);
1695 1696
1696 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2)); 1697 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2));
1697 ASSERT_TRUE(B.good()); 1698 ASSERT_TRUE(B.good());
1698 EXPECT_TRUE(B.Get(IS_UNSYNCED) == false); 1699 EXPECT_TRUE(B.Get(IS_UNSYNCED) == false);
1699 EXPECT_TRUE(B.Get(IS_UNAPPLIED_UPDATE) == false); 1700 EXPECT_TRUE(B.Get(IS_UNAPPLIED_UPDATE) == false);
1700 EXPECT_TRUE(B.Get(SERVER_VERSION) == 20); 1701 EXPECT_TRUE(B.Get(SERVER_VERSION) == 20);
1701 } 1702 }
1702 } 1703 }
1703 1704
1704 TEST_F(SyncerTest, ConflictMatchingEntryHandlesNormalNames) { 1705 TEST_F(SyncerTest, ConflictMatchingEntryHandlesNormalNames) {
1705 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 1706 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
1706 CHECK(dir.good()); 1707 CHECK(dir.good());
1707 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); 1708 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10);
1708 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); 1709 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10);
1709 mock_server_->set_conflict_all_commits(true); 1710 mock_server_->set_conflict_all_commits(true);
1710 SyncShareAsDelegate(); 1711 SyncShareAsDelegate();
1711 { 1712 {
1712 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 1713 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
1713 1714
1714 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 1715 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
1715 ASSERT_TRUE(A.good()); 1716 ASSERT_TRUE(A.good());
1716 A.Put(IS_UNSYNCED, true); 1717 A.Put(IS_UNSYNCED, true);
1717 A.Put(IS_UNAPPLIED_UPDATE, true); 1718 A.Put(IS_UNAPPLIED_UPDATE, true);
1718 A.Put(SERVER_VERSION, 20); 1719 A.Put(SERVER_VERSION, 20);
1719 1720
1720 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 1721 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
1721 ASSERT_TRUE(B.good()); 1722 ASSERT_TRUE(B.good());
1722 B.Put(IS_UNAPPLIED_UPDATE, true); 1723 B.Put(IS_UNAPPLIED_UPDATE, true);
1723 B.Put(SERVER_VERSION, 20); 1724 B.Put(SERVER_VERSION, 20);
1724 } 1725 }
1725 LoopSyncShare(); 1726 LoopSyncShare();
1726 saw_syncer_event_ = false; 1727 saw_syncer_event_ = false;
1727 mock_server_->set_conflict_all_commits(false); 1728 mock_server_->set_conflict_all_commits(false);
1728 1729
1729 { 1730 {
1730 ReadTransaction trans(dir, __FILE__, __LINE__); 1731 ReadTransaction trans(dir, FROM_HERE);
1731 1732
1732 Entry A(&trans, GET_BY_ID, ids_.FromNumber(1)); 1733 Entry A(&trans, GET_BY_ID, ids_.FromNumber(1));
1733 ASSERT_TRUE(A.good()); 1734 ASSERT_TRUE(A.good());
1734 EXPECT_TRUE(A.Get(IS_UNSYNCED) == false); 1735 EXPECT_TRUE(A.Get(IS_UNSYNCED) == false);
1735 EXPECT_TRUE(A.Get(IS_UNAPPLIED_UPDATE) == false); 1736 EXPECT_TRUE(A.Get(IS_UNAPPLIED_UPDATE) == false);
1736 EXPECT_TRUE(A.Get(SERVER_VERSION) == 20); 1737 EXPECT_TRUE(A.Get(SERVER_VERSION) == 20);
1737 1738
1738 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2)); 1739 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2));
1739 ASSERT_TRUE(B.good()); 1740 ASSERT_TRUE(B.good());
1740 EXPECT_TRUE(B.Get(IS_UNSYNCED) == false); 1741 EXPECT_TRUE(B.Get(IS_UNSYNCED) == false);
1741 EXPECT_TRUE(B.Get(IS_UNAPPLIED_UPDATE) == false); 1742 EXPECT_TRUE(B.Get(IS_UNAPPLIED_UPDATE) == false);
1742 EXPECT_TRUE(B.Get(SERVER_VERSION) == 20); 1743 EXPECT_TRUE(B.Get(SERVER_VERSION) == 20);
1743 } 1744 }
1744 } 1745 }
1745 1746
1746 TEST_F(SyncerTest, ReverseFolderOrderingTest) { 1747 TEST_F(SyncerTest, ReverseFolderOrderingTest) {
1747 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 1748 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
1748 ASSERT_TRUE(dir.good()); 1749 ASSERT_TRUE(dir.good());
1749 mock_server_->AddUpdateDirectory(4, 3, "ggchild", 10, 10); 1750 mock_server_->AddUpdateDirectory(4, 3, "ggchild", 10, 10);
1750 mock_server_->AddUpdateDirectory(3, 2, "gchild", 10, 10); 1751 mock_server_->AddUpdateDirectory(3, 2, "gchild", 10, 10);
1751 mock_server_->AddUpdateDirectory(5, 4, "gggchild", 10, 10); 1752 mock_server_->AddUpdateDirectory(5, 4, "gggchild", 10, 10);
1752 mock_server_->AddUpdateDirectory(2, 1, "child", 10, 10); 1753 mock_server_->AddUpdateDirectory(2, 1, "child", 10, 10);
1753 mock_server_->AddUpdateDirectory(1, 0, "parent", 10, 10); 1754 mock_server_->AddUpdateDirectory(1, 0, "parent", 10, 10);
1754 LoopSyncShare(); 1755 LoopSyncShare();
1755 ReadTransaction trans(dir, __FILE__, __LINE__); 1756 ReadTransaction trans(dir, FROM_HERE);
1756 1757
1757 Id child_id = GetOnlyEntryWithName( 1758 Id child_id = GetOnlyEntryWithName(
1758 &trans, ids_.FromNumber(4), "gggchild"); 1759 &trans, ids_.FromNumber(4), "gggchild");
1759 Entry child(&trans, GET_BY_ID, child_id); 1760 Entry child(&trans, GET_BY_ID, child_id);
1760 ASSERT_TRUE(child.good()); 1761 ASSERT_TRUE(child.good());
1761 } 1762 }
1762 1763
1763 class EntryCreatedInNewFolderTest : public SyncerTest { 1764 class EntryCreatedInNewFolderTest : public SyncerTest {
1764 public: 1765 public:
1765 void CreateFolderInBob() { 1766 void CreateFolderInBob() {
1766 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 1767 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
1767 CHECK(dir.good()); 1768 CHECK(dir.good());
1768 1769
1769 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 1770 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
1770 MutableEntry bob(&trans, 1771 MutableEntry bob(&trans,
1771 syncable::GET_BY_ID, 1772 syncable::GET_BY_ID,
1772 GetOnlyEntryWithName(&trans, 1773 GetOnlyEntryWithName(&trans,
1773 TestIdFactory::root(), 1774 TestIdFactory::root(),
1774 "bob")); 1775 "bob"));
1775 CHECK(bob.good()); 1776 CHECK(bob.good());
1776 1777
1777 MutableEntry entry2(&trans, syncable::CREATE, bob.Get(syncable::ID), 1778 MutableEntry entry2(&trans, syncable::CREATE, bob.Get(syncable::ID),
1778 "bob"); 1779 "bob");
1779 CHECK(entry2.good()); 1780 CHECK(entry2.good());
1780 entry2.Put(syncable::IS_DIR, true); 1781 entry2.Put(syncable::IS_DIR, true);
1781 entry2.Put(syncable::IS_UNSYNCED, true); 1782 entry2.Put(syncable::IS_UNSYNCED, true);
1782 entry2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1783 entry2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1783 } 1784 }
1784 }; 1785 };
1785 1786
1786 TEST_F(EntryCreatedInNewFolderTest, EntryCreatedInNewFolderMidSync) { 1787 TEST_F(EntryCreatedInNewFolderTest, EntryCreatedInNewFolderMidSync) {
1787 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 1788 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
1788 ASSERT_TRUE(dir.good()); 1789 ASSERT_TRUE(dir.good());
1789 dir->set_store_birthday(mock_server_->store_birthday()); 1790 dir->set_store_birthday(mock_server_->store_birthday());
1790 { 1791 {
1791 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 1792 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
1792 MutableEntry entry(&trans, syncable::CREATE, trans.root_id(), 1793 MutableEntry entry(&trans, syncable::CREATE, trans.root_id(),
1793 "bob"); 1794 "bob");
1794 ASSERT_TRUE(entry.good()); 1795 ASSERT_TRUE(entry.good());
1795 entry.Put(syncable::IS_DIR, true); 1796 entry.Put(syncable::IS_DIR, true);
1796 entry.Put(syncable::IS_UNSYNCED, true); 1797 entry.Put(syncable::IS_UNSYNCED, true);
1797 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1798 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1798 } 1799 }
1799 1800
1800 mock_server_->SetMidCommitCallback( 1801 mock_server_->SetMidCommitCallback(
1801 NewCallback<EntryCreatedInNewFolderTest>(this, 1802 NewCallback<EntryCreatedInNewFolderTest>(this,
1802 &EntryCreatedInNewFolderTest::CreateFolderInBob)); 1803 &EntryCreatedInNewFolderTest::CreateFolderInBob));
1803 syncer_->SyncShare(session_.get(), BUILD_COMMIT_REQUEST, SYNCER_END); 1804 syncer_->SyncShare(session_.get(), BUILD_COMMIT_REQUEST, SYNCER_END);
1804 EXPECT_TRUE(1 == mock_server_->committed_ids().size()); 1805 EXPECT_TRUE(1 == mock_server_->committed_ids().size());
1805 { 1806 {
1806 ReadTransaction trans(dir, __FILE__, __LINE__); 1807 ReadTransaction trans(dir, FROM_HERE);
1807 Entry parent_entry(&trans, syncable::GET_BY_ID, 1808 Entry parent_entry(&trans, syncable::GET_BY_ID,
1808 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob")); 1809 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob"));
1809 ASSERT_TRUE(parent_entry.good()); 1810 ASSERT_TRUE(parent_entry.good());
1810 1811
1811 Id child_id = 1812 Id child_id =
1812 GetOnlyEntryWithName(&trans, parent_entry.Get(ID), "bob"); 1813 GetOnlyEntryWithName(&trans, parent_entry.Get(ID), "bob");
1813 Entry child(&trans, syncable::GET_BY_ID, child_id); 1814 Entry child(&trans, syncable::GET_BY_ID, child_id);
1814 ASSERT_TRUE(child.good()); 1815 ASSERT_TRUE(child.good());
1815 EXPECT_EQ(parent_entry.Get(ID), child.Get(PARENT_ID)); 1816 EXPECT_EQ(parent_entry.Get(ID), child.Get(PARENT_ID));
1816 } 1817 }
1817 } 1818 }
1818 1819
1819 TEST_F(SyncerTest, NegativeIDInUpdate) { 1820 TEST_F(SyncerTest, NegativeIDInUpdate) {
1820 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 1821 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
1821 CHECK(dir.good()); 1822 CHECK(dir.good());
1822 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40); 1823 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40);
1823 SyncShareAsDelegate(); 1824 SyncShareAsDelegate();
1824 // The negative id would make us CHECK! 1825 // The negative id would make us CHECK!
1825 } 1826 }
1826 1827
1827 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) { 1828 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) {
1828 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 1829 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
1829 CHECK(dir.good()); 1830 CHECK(dir.good());
1830 1831
1831 int64 metahandle_fred; 1832 int64 metahandle_fred;
1832 { 1833 {
1833 // Create an item. 1834 // Create an item.
1834 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 1835 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
1835 MutableEntry fred_match(&trans, CREATE, trans.root_id(), 1836 MutableEntry fred_match(&trans, CREATE, trans.root_id(),
1836 "fred_match"); 1837 "fred_match");
1837 ASSERT_TRUE(fred_match.good()); 1838 ASSERT_TRUE(fred_match.good());
1838 metahandle_fred = fred_match.Get(META_HANDLE); 1839 metahandle_fred = fred_match.Get(META_HANDLE);
1839 WriteTestDataToEntry(&trans, &fred_match); 1840 WriteTestDataToEntry(&trans, &fred_match);
1840 } 1841 }
1841 // Commit it. 1842 // Commit it.
1842 SyncShareAsDelegate(); 1843 SyncShareAsDelegate();
1843 EXPECT_TRUE(1 == mock_server_->committed_ids().size()); 1844 EXPECT_TRUE(1 == mock_server_->committed_ids().size());
1844 mock_server_->set_conflict_all_commits(true); 1845 mock_server_->set_conflict_all_commits(true);
1845 syncable::Id fred_match_id; 1846 syncable::Id fred_match_id;
1846 { 1847 {
1847 // Now receive a change from outside. 1848 // Now receive a change from outside.
1848 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 1849 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
1849 MutableEntry fred_match(&trans, GET_BY_HANDLE, metahandle_fred); 1850 MutableEntry fred_match(&trans, GET_BY_HANDLE, metahandle_fred);
1850 ASSERT_TRUE(fred_match.good()); 1851 ASSERT_TRUE(fred_match.good());
1851 EXPECT_TRUE(fred_match.Get(ID).ServerKnows()); 1852 EXPECT_TRUE(fred_match.Get(ID).ServerKnows());
1852 fred_match_id = fred_match.Get(ID); 1853 fred_match_id = fred_match.Get(ID);
1853 mock_server_->AddUpdateBookmark(fred_match_id, trans.root_id(), 1854 mock_server_->AddUpdateBookmark(fred_match_id, trans.root_id(),
1854 "fred_match", 40, 40); 1855 "fred_match", 40, 40);
1855 } 1856 }
1856 // Run the syncer. 1857 // Run the syncer.
1857 for (int i = 0 ; i < 30 ; ++i) { 1858 for (int i = 0 ; i < 30 ; ++i) {
1858 SyncShareAsDelegate(); 1859 SyncShareAsDelegate();
1859 } 1860 }
1860 } 1861 }
1861 1862
1862 /** 1863 /**
1863 * In the event that we have a double changed entry, that is changed on both 1864 * In the event that we have a double changed entry, that is changed on both
1864 * the client and the server, the conflict resolver should just drop one of 1865 * the client and the server, the conflict resolver should just drop one of
1865 * them and accept the other. 1866 * them and accept the other.
1866 */ 1867 */
1867 1868
1868 TEST_F(SyncerTest, DoublyChangedWithResolver) { 1869 TEST_F(SyncerTest, DoublyChangedWithResolver) {
1869 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 1870 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
1870 CHECK(dir.good()); 1871 CHECK(dir.good());
1871 { 1872 {
1872 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 1873 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
1873 MutableEntry parent(&wtrans, syncable::CREATE, root_id_, "Folder"); 1874 MutableEntry parent(&wtrans, syncable::CREATE, root_id_, "Folder");
1874 ASSERT_TRUE(parent.good()); 1875 ASSERT_TRUE(parent.good());
1875 parent.Put(syncable::IS_DIR, true); 1876 parent.Put(syncable::IS_DIR, true);
1876 parent.Put(syncable::ID, parent_id_); 1877 parent.Put(syncable::ID, parent_id_);
1877 parent.Put(syncable::BASE_VERSION, 5); 1878 parent.Put(syncable::BASE_VERSION, 5);
1878 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1879 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1879 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete.htm"); 1880 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete.htm");
1880 ASSERT_TRUE(child.good()); 1881 ASSERT_TRUE(child.good());
1881 child.Put(syncable::ID, child_id_); 1882 child.Put(syncable::ID, child_id_);
1882 child.Put(syncable::BASE_VERSION, 10); 1883 child.Put(syncable::BASE_VERSION, 10);
1883 WriteTestDataToEntry(&wtrans, &child); 1884 WriteTestDataToEntry(&wtrans, &child);
1884 } 1885 }
1885 mock_server_->AddUpdateBookmark(child_id_, parent_id_, "Pete2.htm", 11, 10); 1886 mock_server_->AddUpdateBookmark(child_id_, parent_id_, "Pete2.htm", 11, 10);
1886 mock_server_->set_conflict_all_commits(true); 1887 mock_server_->set_conflict_all_commits(true);
1887 LoopSyncShare(); 1888 LoopSyncShare();
1888 syncable::Directory::ChildHandles children; 1889 syncable::Directory::ChildHandles children;
1889 { 1890 {
1890 ReadTransaction trans(dir, __FILE__, __LINE__); 1891 ReadTransaction trans(dir, FROM_HERE);
1891 dir->GetChildHandlesById(&trans, parent_id_, &children); 1892 dir->GetChildHandlesById(&trans, parent_id_, &children);
1892 // We expect the conflict resolver to preserve the local entry. 1893 // We expect the conflict resolver to preserve the local entry.
1893 Entry child(&trans, syncable::GET_BY_ID, child_id_); 1894 Entry child(&trans, syncable::GET_BY_ID, child_id_);
1894 ASSERT_TRUE(child.good()); 1895 ASSERT_TRUE(child.good());
1895 EXPECT_TRUE(child.Get(syncable::IS_UNSYNCED)); 1896 EXPECT_TRUE(child.Get(syncable::IS_UNSYNCED));
1896 EXPECT_FALSE(child.Get(syncable::IS_UNAPPLIED_UPDATE)); 1897 EXPECT_FALSE(child.Get(syncable::IS_UNAPPLIED_UPDATE));
1897 EXPECT_TRUE(child.Get(SPECIFICS).HasExtension(sync_pb::bookmark)); 1898 EXPECT_TRUE(child.Get(SPECIFICS).HasExtension(sync_pb::bookmark));
1898 EXPECT_EQ("Pete.htm", child.Get(NON_UNIQUE_NAME)); 1899 EXPECT_EQ("Pete.htm", child.Get(NON_UNIQUE_NAME));
1899 VerifyTestBookmarkDataInEntry(&child); 1900 VerifyTestBookmarkDataInEntry(&child);
1900 } 1901 }
1901 1902
1902 // Only one entry, since we just overwrite one. 1903 // Only one entry, since we just overwrite one.
1903 EXPECT_TRUE(1 == children.size()); 1904 EXPECT_TRUE(1 == children.size());
1904 saw_syncer_event_ = false; 1905 saw_syncer_event_ = false;
1905 } 1906 }
1906 1907
1907 // We got this repro case when someone was editing bookmarks while sync was 1908 // We got this repro case when someone was editing bookmarks while sync was
1908 // occuring. The entry had changed out underneath the user. 1909 // occuring. The entry had changed out underneath the user.
1909 TEST_F(SyncerTest, CommitsUpdateDoesntAlterEntry) { 1910 TEST_F(SyncerTest, CommitsUpdateDoesntAlterEntry) {
1910 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 1911 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
1911 CHECK(dir.good()); 1912 CHECK(dir.good());
1912 int64 test_time = 123456; 1913 int64 test_time = 123456;
1913 int64 entry_metahandle; 1914 int64 entry_metahandle;
1914 { 1915 {
1915 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 1916 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
1916 MutableEntry entry(&wtrans, syncable::CREATE, root_id_, "Pete"); 1917 MutableEntry entry(&wtrans, syncable::CREATE, root_id_, "Pete");
1917 ASSERT_TRUE(entry.good()); 1918 ASSERT_TRUE(entry.good());
1918 EXPECT_FALSE(entry.Get(ID).ServerKnows()); 1919 EXPECT_FALSE(entry.Get(ID).ServerKnows());
1919 entry.Put(syncable::IS_DIR, true); 1920 entry.Put(syncable::IS_DIR, true);
1920 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1921 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1921 entry.Put(syncable::IS_UNSYNCED, true); 1922 entry.Put(syncable::IS_UNSYNCED, true);
1922 entry.Put(syncable::MTIME, test_time); 1923 entry.Put(syncable::MTIME, test_time);
1923 entry_metahandle = entry.Get(META_HANDLE); 1924 entry_metahandle = entry.Get(META_HANDLE);
1924 } 1925 }
1925 SyncShareAsDelegate(); 1926 SyncShareAsDelegate();
1926 syncable::Id id; 1927 syncable::Id id;
1927 int64 version; 1928 int64 version;
1928 int64 server_position_in_parent; 1929 int64 server_position_in_parent;
1929 { 1930 {
1930 ReadTransaction trans(dir, __FILE__, __LINE__); 1931 ReadTransaction trans(dir, FROM_HERE);
1931 Entry entry(&trans, syncable::GET_BY_HANDLE, entry_metahandle); 1932 Entry entry(&trans, syncable::GET_BY_HANDLE, entry_metahandle);
1932 ASSERT_TRUE(entry.good()); 1933 ASSERT_TRUE(entry.good());
1933 id = entry.Get(ID); 1934 id = entry.Get(ID);
1934 EXPECT_TRUE(id.ServerKnows()); 1935 EXPECT_TRUE(id.ServerKnows());
1935 version = entry.Get(BASE_VERSION); 1936 version = entry.Get(BASE_VERSION);
1936 server_position_in_parent = entry.Get(SERVER_POSITION_IN_PARENT); 1937 server_position_in_parent = entry.Get(SERVER_POSITION_IN_PARENT);
1937 } 1938 }
1938 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit(); 1939 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit();
1939 EXPECT_EQ("Pete", update->name()); 1940 EXPECT_EQ("Pete", update->name());
1940 EXPECT_EQ(id.GetServerId(), update->id_string()); 1941 EXPECT_EQ(id.GetServerId(), update->id_string());
1941 EXPECT_EQ(root_id_.GetServerId(), update->parent_id_string()); 1942 EXPECT_EQ(root_id_.GetServerId(), update->parent_id_string());
1942 EXPECT_EQ(version, update->version()); 1943 EXPECT_EQ(version, update->version());
1943 EXPECT_EQ(server_position_in_parent, update->position_in_parent()); 1944 EXPECT_EQ(server_position_in_parent, update->position_in_parent());
1944 SyncShareAsDelegate(); 1945 SyncShareAsDelegate();
1945 { 1946 {
1946 ReadTransaction trans(dir, __FILE__, __LINE__); 1947 ReadTransaction trans(dir, FROM_HERE);
1947 Entry entry(&trans, syncable::GET_BY_ID, id); 1948 Entry entry(&trans, syncable::GET_BY_ID, id);
1948 ASSERT_TRUE(entry.good()); 1949 ASSERT_TRUE(entry.good());
1949 EXPECT_TRUE(entry.Get(MTIME) == test_time); 1950 EXPECT_TRUE(entry.Get(MTIME) == test_time);
1950 } 1951 }
1951 } 1952 }
1952 1953
1953 TEST_F(SyncerTest, ParentAndChildBothMatch) { 1954 TEST_F(SyncerTest, ParentAndChildBothMatch) {
1954 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 1955 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
1955 CHECK(dir.good()); 1956 CHECK(dir.good());
1956 syncable::Id parent_id = ids_.NewServerId(); 1957 syncable::Id parent_id = ids_.NewServerId();
1957 syncable::Id child_id = ids_.NewServerId(); 1958 syncable::Id child_id = ids_.NewServerId();
1958 1959
1959 { 1960 {
1960 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 1961 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
1961 MutableEntry parent(&wtrans, CREATE, root_id_, "Folder"); 1962 MutableEntry parent(&wtrans, CREATE, root_id_, "Folder");
1962 ASSERT_TRUE(parent.good()); 1963 ASSERT_TRUE(parent.good());
1963 parent.Put(IS_DIR, true); 1964 parent.Put(IS_DIR, true);
1964 parent.Put(IS_UNSYNCED, true); 1965 parent.Put(IS_UNSYNCED, true);
1965 parent.Put(ID, parent_id); 1966 parent.Put(ID, parent_id);
1966 parent.Put(BASE_VERSION, 1); 1967 parent.Put(BASE_VERSION, 1);
1967 parent.Put(SPECIFICS, DefaultBookmarkSpecifics()); 1968 parent.Put(SPECIFICS, DefaultBookmarkSpecifics());
1968 1969
1969 MutableEntry child(&wtrans, CREATE, parent.Get(ID), "test.htm"); 1970 MutableEntry child(&wtrans, CREATE, parent.Get(ID), "test.htm");
1970 ASSERT_TRUE(child.good()); 1971 ASSERT_TRUE(child.good());
1971 child.Put(ID, child_id); 1972 child.Put(ID, child_id);
1972 child.Put(BASE_VERSION, 1); 1973 child.Put(BASE_VERSION, 1);
1973 child.Put(SPECIFICS, DefaultBookmarkSpecifics()); 1974 child.Put(SPECIFICS, DefaultBookmarkSpecifics());
1974 WriteTestDataToEntry(&wtrans, &child); 1975 WriteTestDataToEntry(&wtrans, &child);
1975 } 1976 }
1976 mock_server_->AddUpdateDirectory(parent_id, root_id_, "Folder", 10, 10); 1977 mock_server_->AddUpdateDirectory(parent_id, root_id_, "Folder", 10, 10);
1977 mock_server_->AddUpdateBookmark(child_id, parent_id, "test.htm", 10, 10); 1978 mock_server_->AddUpdateBookmark(child_id, parent_id, "test.htm", 10, 10);
1978 mock_server_->set_conflict_all_commits(true); 1979 mock_server_->set_conflict_all_commits(true);
1979 SyncShareAsDelegate(); 1980 SyncShareAsDelegate();
1980 SyncShareAsDelegate(); 1981 SyncShareAsDelegate();
1981 SyncShareAsDelegate(); 1982 SyncShareAsDelegate();
1982 { 1983 {
1983 ReadTransaction trans(dir, __FILE__, __LINE__); 1984 ReadTransaction trans(dir, FROM_HERE);
1984 Directory::ChildHandles children; 1985 Directory::ChildHandles children;
1985 dir->GetChildHandlesById(&trans, root_id_, &children); 1986 dir->GetChildHandlesById(&trans, root_id_, &children);
1986 EXPECT_TRUE(1 == children.size()); 1987 EXPECT_TRUE(1 == children.size());
1987 dir->GetChildHandlesById(&trans, parent_id, &children); 1988 dir->GetChildHandlesById(&trans, parent_id, &children);
1988 EXPECT_TRUE(1 == children.size()); 1989 EXPECT_TRUE(1 == children.size());
1989 Directory::UnappliedUpdateMetaHandles unapplied; 1990 Directory::UnappliedUpdateMetaHandles unapplied;
1990 dir->GetUnappliedUpdateMetaHandles(&trans, &unapplied); 1991 dir->GetUnappliedUpdateMetaHandles(&trans, &unapplied);
1991 EXPECT_TRUE(0 == unapplied.size()); 1992 EXPECT_TRUE(0 == unapplied.size());
1992 syncable::Directory::UnsyncedMetaHandles unsynced; 1993 syncable::Directory::UnsyncedMetaHandles unsynced;
1993 dir->GetUnsyncedMetaHandles(&trans, &unsynced); 1994 dir->GetUnsyncedMetaHandles(&trans, &unsynced);
1994 EXPECT_TRUE(0 == unsynced.size()); 1995 EXPECT_TRUE(0 == unsynced.size());
1995 saw_syncer_event_ = false; 1996 saw_syncer_event_ = false;
1996 } 1997 }
1997 } 1998 }
1998 1999
1999 TEST_F(SyncerTest, CommittingNewDeleted) { 2000 TEST_F(SyncerTest, CommittingNewDeleted) {
2000 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2001 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2001 CHECK(dir.good()); 2002 CHECK(dir.good());
2002 { 2003 {
2003 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2004 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2004 MutableEntry entry(&trans, CREATE, trans.root_id(), "bob"); 2005 MutableEntry entry(&trans, CREATE, trans.root_id(), "bob");
2005 entry.Put(IS_UNSYNCED, true); 2006 entry.Put(IS_UNSYNCED, true);
2006 entry.Put(IS_DEL, true); 2007 entry.Put(IS_DEL, true);
2007 } 2008 }
2008 SyncShareAsDelegate(); 2009 SyncShareAsDelegate();
2009 EXPECT_TRUE(0 == mock_server_->committed_ids().size()); 2010 EXPECT_TRUE(0 == mock_server_->committed_ids().size());
2010 } 2011 }
2011 2012
2012 // Original problem synopsis: 2013 // Original problem synopsis:
2013 // Check failed: entry->Get(BASE_VERSION) <= entry->Get(SERVER_VERSION) 2014 // Check failed: entry->Get(BASE_VERSION) <= entry->Get(SERVER_VERSION)
2014 // Client creates entry, client finishes committing entry. Between 2015 // Client creates entry, client finishes committing entry. Between
2015 // commit and getting update back, we delete the entry. 2016 // commit and getting update back, we delete the entry.
2016 // We get the update for the entry, but the local one was modified 2017 // We get the update for the entry, but the local one was modified
2017 // so we store the entry but don't apply it. IS_UNAPPLIED_UPDATE is set. 2018 // so we store the entry but don't apply it. IS_UNAPPLIED_UPDATE is set.
2018 // We commit deletion and get a new version number. 2019 // We commit deletion and get a new version number.
2019 // We apply unapplied updates again before we get the update about the deletion. 2020 // We apply unapplied updates again before we get the update about the deletion.
2020 // This means we have an unapplied update where server_version < base_version. 2021 // This means we have an unapplied update where server_version < base_version.
2021 TEST_F(SyncerTest, UnappliedUpdateDuringCommit) { 2022 TEST_F(SyncerTest, UnappliedUpdateDuringCommit) {
2022 // This test is a little fake. 2023 // This test is a little fake.
2023 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2024 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2024 CHECK(dir.good()); 2025 CHECK(dir.good());
2025 { 2026 {
2026 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2027 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2027 MutableEntry entry(&trans, CREATE, trans.root_id(), "bob"); 2028 MutableEntry entry(&trans, CREATE, trans.root_id(), "bob");
2028 entry.Put(ID, ids_.FromNumber(20)); 2029 entry.Put(ID, ids_.FromNumber(20));
2029 entry.Put(BASE_VERSION, 1); 2030 entry.Put(BASE_VERSION, 1);
2030 entry.Put(SERVER_VERSION, 1); 2031 entry.Put(SERVER_VERSION, 1);
2031 entry.Put(SERVER_PARENT_ID, ids_.FromNumber(9999)); // Bad parent. 2032 entry.Put(SERVER_PARENT_ID, ids_.FromNumber(9999)); // Bad parent.
2032 entry.Put(IS_UNSYNCED, true); 2033 entry.Put(IS_UNSYNCED, true);
2033 entry.Put(IS_UNAPPLIED_UPDATE, true); 2034 entry.Put(IS_UNAPPLIED_UPDATE, true);
2034 entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2035 entry.Put(SPECIFICS, DefaultBookmarkSpecifics());
2035 entry.Put(SERVER_SPECIFICS, DefaultBookmarkSpecifics()); 2036 entry.Put(SERVER_SPECIFICS, DefaultBookmarkSpecifics());
2036 entry.Put(IS_DEL, false); 2037 entry.Put(IS_DEL, false);
(...skipping 14 matching lines...) Expand all
2051 // remove bob 2052 // remove bob
2052 // remove fred 2053 // remove fred
2053 // if no syncing occured midway, bob will have an illegal parent 2054 // if no syncing occured midway, bob will have an illegal parent
2054 TEST_F(SyncerTest, DeletingEntryInFolder) { 2055 TEST_F(SyncerTest, DeletingEntryInFolder) {
2055 // This test is a little fake. 2056 // This test is a little fake.
2056 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2057 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2057 CHECK(dir.good()); 2058 CHECK(dir.good());
2058 2059
2059 int64 existing_metahandle; 2060 int64 existing_metahandle;
2060 { 2061 {
2061 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2062 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2062 MutableEntry entry(&trans, CREATE, trans.root_id(), "existing"); 2063 MutableEntry entry(&trans, CREATE, trans.root_id(), "existing");
2063 ASSERT_TRUE(entry.good()); 2064 ASSERT_TRUE(entry.good());
2064 entry.Put(IS_DIR, true); 2065 entry.Put(IS_DIR, true);
2065 entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2066 entry.Put(SPECIFICS, DefaultBookmarkSpecifics());
2066 entry.Put(IS_UNSYNCED, true); 2067 entry.Put(IS_UNSYNCED, true);
2067 existing_metahandle = entry.Get(META_HANDLE); 2068 existing_metahandle = entry.Get(META_HANDLE);
2068 } 2069 }
2069 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 2070 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
2070 { 2071 {
2071 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2072 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2072 MutableEntry newfolder(&trans, CREATE, trans.root_id(), "new"); 2073 MutableEntry newfolder(&trans, CREATE, trans.root_id(), "new");
2073 ASSERT_TRUE(newfolder.good()); 2074 ASSERT_TRUE(newfolder.good());
2074 newfolder.Put(IS_DIR, true); 2075 newfolder.Put(IS_DIR, true);
2075 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2076 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics());
2076 newfolder.Put(IS_UNSYNCED, true); 2077 newfolder.Put(IS_UNSYNCED, true);
2077 2078
2078 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle); 2079 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle);
2079 ASSERT_TRUE(existing.good()); 2080 ASSERT_TRUE(existing.good());
2080 existing.Put(PARENT_ID, newfolder.Get(ID)); 2081 existing.Put(PARENT_ID, newfolder.Get(ID));
2081 existing.Put(IS_UNSYNCED, true); 2082 existing.Put(IS_UNSYNCED, true);
2082 EXPECT_TRUE(existing.Get(ID).ServerKnows()); 2083 EXPECT_TRUE(existing.Get(ID).ServerKnows());
2083 2084
2084 newfolder.Put(IS_DEL, true); 2085 newfolder.Put(IS_DEL, true);
2085 existing.Put(IS_DEL, true); 2086 existing.Put(IS_DEL, true);
2086 } 2087 }
2087 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 2088 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
2088 StatusController* status(session_->status_controller()); 2089 StatusController* status(session_->status_controller());
2089 EXPECT_TRUE(0 == status->error_counters().num_conflicting_commits); 2090 EXPECT_TRUE(0 == status->error_counters().num_conflicting_commits);
2090 } 2091 }
2091 2092
2092 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) { 2093 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) {
2093 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2094 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2094 CHECK(dir.good()); 2095 CHECK(dir.good());
2095 int64 newfolder_metahandle; 2096 int64 newfolder_metahandle;
2096 2097
2097 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); 2098 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10);
2098 SyncShareAsDelegate(); 2099 SyncShareAsDelegate();
2099 { 2100 {
2100 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2101 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2101 MutableEntry newfolder(&trans, CREATE, ids_.FromNumber(1), "local"); 2102 MutableEntry newfolder(&trans, CREATE, ids_.FromNumber(1), "local");
2102 ASSERT_TRUE(newfolder.good()); 2103 ASSERT_TRUE(newfolder.good());
2103 newfolder.Put(IS_UNSYNCED, true); 2104 newfolder.Put(IS_UNSYNCED, true);
2104 newfolder.Put(IS_DIR, true); 2105 newfolder.Put(IS_DIR, true);
2105 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2106 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics());
2106 newfolder_metahandle = newfolder.Get(META_HANDLE); 2107 newfolder_metahandle = newfolder.Get(META_HANDLE);
2107 } 2108 }
2108 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20); 2109 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20);
2109 mock_server_->SetLastUpdateDeleted(); 2110 mock_server_->SetLastUpdateDeleted();
2110 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, APPLY_UPDATES); 2111 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, APPLY_UPDATES);
2111 { 2112 {
2112 ReadTransaction trans(dir, __FILE__, __LINE__); 2113 ReadTransaction trans(dir, FROM_HERE);
2113 Entry entry(&trans, syncable::GET_BY_HANDLE, newfolder_metahandle); 2114 Entry entry(&trans, syncable::GET_BY_HANDLE, newfolder_metahandle);
2114 ASSERT_TRUE(entry.good()); 2115 ASSERT_TRUE(entry.good());
2115 } 2116 }
2116 } 2117 }
2117 2118
2118 TEST_F(SyncerTest, FolderSwapUpdate) { 2119 TEST_F(SyncerTest, FolderSwapUpdate) {
2119 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2120 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2120 CHECK(dir.good()); 2121 CHECK(dir.good());
2121 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10); 2122 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10);
2122 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10); 2123 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10);
2123 SyncShareAsDelegate(); 2124 SyncShareAsDelegate();
2124 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20); 2125 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20);
2125 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20); 2126 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20);
2126 SyncShareAsDelegate(); 2127 SyncShareAsDelegate();
2127 { 2128 {
2128 ReadTransaction trans(dir, __FILE__, __LINE__); 2129 ReadTransaction trans(dir, FROM_HERE);
2129 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); 2130 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801));
2130 ASSERT_TRUE(id1.good()); 2131 ASSERT_TRUE(id1.good());
2131 EXPECT_TRUE("fred" == id1.Get(NON_UNIQUE_NAME)); 2132 EXPECT_TRUE("fred" == id1.Get(NON_UNIQUE_NAME));
2132 EXPECT_TRUE(root_id_ == id1.Get(PARENT_ID)); 2133 EXPECT_TRUE(root_id_ == id1.Get(PARENT_ID));
2133 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); 2134 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024));
2134 ASSERT_TRUE(id2.good()); 2135 ASSERT_TRUE(id2.good());
2135 EXPECT_TRUE("bob" == id2.Get(NON_UNIQUE_NAME)); 2136 EXPECT_TRUE("bob" == id2.Get(NON_UNIQUE_NAME));
2136 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID)); 2137 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID));
2137 } 2138 }
2138 saw_syncer_event_ = false; 2139 saw_syncer_event_ = false;
2139 } 2140 }
2140 2141
2141 TEST_F(SyncerTest, NameCollidingFolderSwapWorksFine) { 2142 TEST_F(SyncerTest, NameCollidingFolderSwapWorksFine) {
2142 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2143 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2143 CHECK(dir.good()); 2144 CHECK(dir.good());
2144 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10); 2145 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10);
2145 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10); 2146 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10);
2146 mock_server_->AddUpdateDirectory(4096, 0, "alice", 1, 10); 2147 mock_server_->AddUpdateDirectory(4096, 0, "alice", 1, 10);
2147 SyncShareAsDelegate(); 2148 SyncShareAsDelegate();
2148 { 2149 {
2149 ReadTransaction trans(dir, __FILE__, __LINE__); 2150 ReadTransaction trans(dir, FROM_HERE);
2150 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); 2151 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801));
2151 ASSERT_TRUE(id1.good()); 2152 ASSERT_TRUE(id1.good());
2152 EXPECT_TRUE("bob" == id1.Get(NON_UNIQUE_NAME)); 2153 EXPECT_TRUE("bob" == id1.Get(NON_UNIQUE_NAME));
2153 EXPECT_TRUE(root_id_ == id1.Get(PARENT_ID)); 2154 EXPECT_TRUE(root_id_ == id1.Get(PARENT_ID));
2154 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); 2155 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024));
2155 ASSERT_TRUE(id2.good()); 2156 ASSERT_TRUE(id2.good());
2156 EXPECT_TRUE("fred" == id2.Get(NON_UNIQUE_NAME)); 2157 EXPECT_TRUE("fred" == id2.Get(NON_UNIQUE_NAME));
2157 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID)); 2158 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID));
2158 Entry id3(&trans, GET_BY_ID, ids_.FromNumber(4096)); 2159 Entry id3(&trans, GET_BY_ID, ids_.FromNumber(4096));
2159 ASSERT_TRUE(id3.good()); 2160 ASSERT_TRUE(id3.good());
2160 EXPECT_TRUE("alice" == id3.Get(NON_UNIQUE_NAME)); 2161 EXPECT_TRUE("alice" == id3.Get(NON_UNIQUE_NAME));
2161 EXPECT_TRUE(root_id_ == id3.Get(PARENT_ID)); 2162 EXPECT_TRUE(root_id_ == id3.Get(PARENT_ID));
2162 } 2163 }
2163 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20); 2164 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20);
2164 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20); 2165 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20);
2165 mock_server_->AddUpdateDirectory(4096, 0, "bob", 2, 20); 2166 mock_server_->AddUpdateDirectory(4096, 0, "bob", 2, 20);
2166 SyncShareAsDelegate(); 2167 SyncShareAsDelegate();
2167 { 2168 {
2168 ReadTransaction trans(dir, __FILE__, __LINE__); 2169 ReadTransaction trans(dir, FROM_HERE);
2169 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); 2170 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801));
2170 ASSERT_TRUE(id1.good()); 2171 ASSERT_TRUE(id1.good());
2171 EXPECT_TRUE("fred" == id1.Get(NON_UNIQUE_NAME)); 2172 EXPECT_TRUE("fred" == id1.Get(NON_UNIQUE_NAME));
2172 EXPECT_TRUE(root_id_ == id1.Get(PARENT_ID)); 2173 EXPECT_TRUE(root_id_ == id1.Get(PARENT_ID));
2173 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); 2174 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024));
2174 ASSERT_TRUE(id2.good()); 2175 ASSERT_TRUE(id2.good());
2175 EXPECT_TRUE("bob" == id2.Get(NON_UNIQUE_NAME)); 2176 EXPECT_TRUE("bob" == id2.Get(NON_UNIQUE_NAME));
2176 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID)); 2177 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID));
2177 Entry id3(&trans, GET_BY_ID, ids_.FromNumber(4096)); 2178 Entry id3(&trans, GET_BY_ID, ids_.FromNumber(4096));
2178 ASSERT_TRUE(id3.good()); 2179 ASSERT_TRUE(id3.good());
2179 EXPECT_TRUE("bob" == id3.Get(NON_UNIQUE_NAME)); 2180 EXPECT_TRUE("bob" == id3.Get(NON_UNIQUE_NAME));
2180 EXPECT_TRUE(root_id_ == id3.Get(PARENT_ID)); 2181 EXPECT_TRUE(root_id_ == id3.Get(PARENT_ID));
2181 } 2182 }
2182 saw_syncer_event_ = false; 2183 saw_syncer_event_ = false;
2183 } 2184 }
2184 2185
2185 TEST_F(SyncerTest, CommitManyItemsInOneGo) { 2186 TEST_F(SyncerTest, CommitManyItemsInOneGo) {
2186 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2187 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2187 uint32 max_batches = 3; 2188 uint32 max_batches = 3;
2188 uint32 items_to_commit = kDefaultMaxCommitBatchSize * max_batches; 2189 uint32 items_to_commit = kDefaultMaxCommitBatchSize * max_batches;
2189 CHECK(dir.good()); 2190 CHECK(dir.good());
2190 { 2191 {
2191 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2192 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2192 for (uint32 i = 0; i < items_to_commit; i++) { 2193 for (uint32 i = 0; i < items_to_commit; i++) {
2193 string nameutf8 = base::StringPrintf("%d", i); 2194 string nameutf8 = base::StringPrintf("%d", i);
2194 string name(nameutf8.begin(), nameutf8.end()); 2195 string name(nameutf8.begin(), nameutf8.end());
2195 MutableEntry e(&trans, CREATE, trans.root_id(), name); 2196 MutableEntry e(&trans, CREATE, trans.root_id(), name);
2196 e.Put(IS_UNSYNCED, true); 2197 e.Put(IS_UNSYNCED, true);
2197 e.Put(IS_DIR, true); 2198 e.Put(IS_DIR, true);
2198 e.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2199 e.Put(SPECIFICS, DefaultBookmarkSpecifics());
2199 } 2200 }
2200 } 2201 }
2201 uint32 num_loops = 0; 2202 uint32 num_loops = 0;
2202 while (SyncShareAsDelegate()) { 2203 while (SyncShareAsDelegate()) {
2203 num_loops++; 2204 num_loops++;
2204 ASSERT_LT(num_loops, max_batches * 2); 2205 ASSERT_LT(num_loops, max_batches * 2);
2205 } 2206 }
2206 EXPECT_GE(mock_server_->commit_messages().size(), max_batches); 2207 EXPECT_GE(mock_server_->commit_messages().size(), max_batches);
2207 } 2208 }
2208 2209
2209 TEST_F(SyncerTest, HugeConflict) { 2210 TEST_F(SyncerTest, HugeConflict) {
2210 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2211 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2211 int item_count = 300; // We should be able to do 300 or 3000 w/o issue. 2212 int item_count = 300; // We should be able to do 300 or 3000 w/o issue.
2212 CHECK(dir.good()); 2213 CHECK(dir.good());
2213 2214
2214 syncable::Id parent_id = ids_.NewServerId(); 2215 syncable::Id parent_id = ids_.NewServerId();
2215 syncable::Id last_id = parent_id; 2216 syncable::Id last_id = parent_id;
2216 vector<syncable::Id> tree_ids; 2217 vector<syncable::Id> tree_ids;
2217 2218
2218 // Create a lot of updates for which the parent does not exist yet. 2219 // Create a lot of updates for which the parent does not exist yet.
2219 // Generate a huge deep tree which should all fail to apply at first. 2220 // Generate a huge deep tree which should all fail to apply at first.
2220 { 2221 {
2221 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2222 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2222 for (int i = 0; i < item_count ; i++) { 2223 for (int i = 0; i < item_count ; i++) {
2223 syncable::Id next_id = ids_.NewServerId(); 2224 syncable::Id next_id = ids_.NewServerId();
2224 tree_ids.push_back(next_id); 2225 tree_ids.push_back(next_id);
2225 mock_server_->AddUpdateDirectory(next_id, last_id, "BOB", 2, 20); 2226 mock_server_->AddUpdateDirectory(next_id, last_id, "BOB", 2, 20);
2226 last_id = next_id; 2227 last_id = next_id;
2227 } 2228 }
2228 } 2229 }
2229 SyncShareAsDelegate(); 2230 SyncShareAsDelegate();
2230 2231
2231 // Check they're in the expected conflict state. 2232 // Check they're in the expected conflict state.
2232 { 2233 {
2233 ReadTransaction trans(dir, __FILE__, __LINE__); 2234 ReadTransaction trans(dir, FROM_HERE);
2234 for (int i = 0; i < item_count; i++) { 2235 for (int i = 0; i < item_count; i++) {
2235 Entry e(&trans, GET_BY_ID, tree_ids[i]); 2236 Entry e(&trans, GET_BY_ID, tree_ids[i]);
2236 // They should all exist but none should be applied. 2237 // They should all exist but none should be applied.
2237 ASSERT_TRUE(e.good()); 2238 ASSERT_TRUE(e.good());
2238 EXPECT_TRUE(e.Get(IS_DEL)); 2239 EXPECT_TRUE(e.Get(IS_DEL));
2239 EXPECT_TRUE(e.Get(IS_UNAPPLIED_UPDATE)); 2240 EXPECT_TRUE(e.Get(IS_UNAPPLIED_UPDATE));
2240 } 2241 }
2241 } 2242 }
2242 2243
2243 // Add the missing parent directory. 2244 // Add the missing parent directory.
2244 mock_server_->AddUpdateDirectory(parent_id, TestIdFactory::root(), 2245 mock_server_->AddUpdateDirectory(parent_id, TestIdFactory::root(),
2245 "BOB", 2, 20); 2246 "BOB", 2, 20);
2246 SyncShareAsDelegate(); 2247 SyncShareAsDelegate();
2247 2248
2248 // Now they should all be OK. 2249 // Now they should all be OK.
2249 { 2250 {
2250 ReadTransaction trans(dir, __FILE__, __LINE__); 2251 ReadTransaction trans(dir, FROM_HERE);
2251 for (int i = 0; i < item_count; i++) { 2252 for (int i = 0; i < item_count; i++) {
2252 Entry e(&trans, GET_BY_ID, tree_ids[i]); 2253 Entry e(&trans, GET_BY_ID, tree_ids[i]);
2253 ASSERT_TRUE(e.good()); 2254 ASSERT_TRUE(e.good());
2254 EXPECT_FALSE(e.Get(IS_DEL)); 2255 EXPECT_FALSE(e.Get(IS_DEL));
2255 EXPECT_FALSE(e.Get(IS_UNAPPLIED_UPDATE)); 2256 EXPECT_FALSE(e.Get(IS_UNAPPLIED_UPDATE));
2256 } 2257 }
2257 } 2258 }
2258 } 2259 }
2259 2260
2260 TEST_F(SyncerTest, DontCrashOnCaseChange) { 2261 TEST_F(SyncerTest, DontCrashOnCaseChange) {
2261 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2262 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2262 CHECK(dir.good()); 2263 CHECK(dir.good());
2263 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); 2264 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10);
2264 SyncShareAsDelegate(); 2265 SyncShareAsDelegate();
2265 { 2266 {
2266 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2267 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2267 MutableEntry e(&trans, GET_BY_ID, ids_.FromNumber(1)); 2268 MutableEntry e(&trans, GET_BY_ID, ids_.FromNumber(1));
2268 ASSERT_TRUE(e.good()); 2269 ASSERT_TRUE(e.good());
2269 e.Put(IS_UNSYNCED, true); 2270 e.Put(IS_UNSYNCED, true);
2270 } 2271 }
2271 mock_server_->set_conflict_all_commits(true); 2272 mock_server_->set_conflict_all_commits(true);
2272 mock_server_->AddUpdateDirectory(1, 0, "BOB", 2, 20); 2273 mock_server_->AddUpdateDirectory(1, 0, "BOB", 2, 20);
2273 SyncShareAsDelegate(); // USED TO CAUSE AN ASSERT 2274 SyncShareAsDelegate(); // USED TO CAUSE AN ASSERT
2274 saw_syncer_event_ = false; 2275 saw_syncer_event_ = false;
2275 } 2276 }
2276 2277
2277 TEST_F(SyncerTest, UnsyncedItemAndUpdate) { 2278 TEST_F(SyncerTest, UnsyncedItemAndUpdate) {
2278 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2279 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2279 CHECK(dir.good()); 2280 CHECK(dir.good());
2280 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); 2281 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10);
2281 SyncShareAsDelegate(); 2282 SyncShareAsDelegate();
2282 mock_server_->set_conflict_all_commits(true); 2283 mock_server_->set_conflict_all_commits(true);
2283 mock_server_->AddUpdateDirectory(2, 0, "bob", 2, 20); 2284 mock_server_->AddUpdateDirectory(2, 0, "bob", 2, 20);
2284 SyncShareAsDelegate(); // USED TO CAUSE AN ASSERT 2285 SyncShareAsDelegate(); // USED TO CAUSE AN ASSERT
2285 saw_syncer_event_ = false; 2286 saw_syncer_event_ = false;
2286 } 2287 }
2287 2288
2288 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath) { 2289 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath) {
2289 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2290 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2290 CHECK(dir.good()); 2291 CHECK(dir.good());
2291 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10); 2292 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10);
2292 SyncShareAsDelegate(); 2293 SyncShareAsDelegate();
2293 int64 local_folder_handle; 2294 int64 local_folder_handle;
2294 syncable::Id local_folder_id; 2295 syncable::Id local_folder_id;
2295 { 2296 {
2296 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 2297 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
2297 MutableEntry new_entry(&wtrans, CREATE, wtrans.root_id(), "Bar.htm"); 2298 MutableEntry new_entry(&wtrans, CREATE, wtrans.root_id(), "Bar.htm");
2298 ASSERT_TRUE(new_entry.good()); 2299 ASSERT_TRUE(new_entry.good());
2299 local_folder_id = new_entry.Get(ID); 2300 local_folder_id = new_entry.Get(ID);
2300 local_folder_handle = new_entry.Get(META_HANDLE); 2301 local_folder_handle = new_entry.Get(META_HANDLE);
2301 new_entry.Put(IS_UNSYNCED, true); 2302 new_entry.Put(IS_UNSYNCED, true);
2302 new_entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2303 new_entry.Put(SPECIFICS, DefaultBookmarkSpecifics());
2303 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2304 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2304 ASSERT_TRUE(old.good()); 2305 ASSERT_TRUE(old.good());
2305 WriteTestDataToEntry(&wtrans, &old); 2306 WriteTestDataToEntry(&wtrans, &old);
2306 } 2307 }
2307 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20); 2308 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20);
2308 mock_server_->set_conflict_all_commits(true); 2309 mock_server_->set_conflict_all_commits(true);
2309 SyncShareAsDelegate(); 2310 SyncShareAsDelegate();
2310 saw_syncer_event_ = false; 2311 saw_syncer_event_ = false;
2311 { 2312 {
2312 // Update #20 should have been dropped in favor of the local version. 2313 // Update #20 should have been dropped in favor of the local version.
2313 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 2314 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
2314 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2315 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2315 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); 2316 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle);
2316 ASSERT_TRUE(server.good()); 2317 ASSERT_TRUE(server.good());
2317 ASSERT_TRUE(local.good()); 2318 ASSERT_TRUE(local.good());
2318 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE)); 2319 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE));
2319 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE)); 2320 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE));
2320 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE)); 2321 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE));
2321 EXPECT_TRUE(server.Get(IS_UNSYNCED)); 2322 EXPECT_TRUE(server.Get(IS_UNSYNCED));
2322 EXPECT_TRUE(local.Get(IS_UNSYNCED)); 2323 EXPECT_TRUE(local.Get(IS_UNSYNCED));
2323 EXPECT_EQ("Foo.htm", server.Get(NON_UNIQUE_NAME)); 2324 EXPECT_EQ("Foo.htm", server.Get(NON_UNIQUE_NAME));
2324 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME)); 2325 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME));
2325 } 2326 }
2326 // Allow local changes to commit. 2327 // Allow local changes to commit.
2327 mock_server_->set_conflict_all_commits(false); 2328 mock_server_->set_conflict_all_commits(false);
2328 SyncShareAsDelegate(); 2329 SyncShareAsDelegate();
2329 saw_syncer_event_ = false; 2330 saw_syncer_event_ = false;
2330 2331
2331 // Now add a server change to make the two names equal. There should 2332 // Now add a server change to make the two names equal. There should
2332 // be no conflict with that, since names are not unique. 2333 // be no conflict with that, since names are not unique.
2333 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30); 2334 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30);
2334 SyncShareAsDelegate(); 2335 SyncShareAsDelegate();
2335 saw_syncer_event_ = false; 2336 saw_syncer_event_ = false;
2336 { 2337 {
2337 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 2338 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
2338 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2339 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2339 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); 2340 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle);
2340 ASSERT_TRUE(server.good()); 2341 ASSERT_TRUE(server.good());
2341 ASSERT_TRUE(local.good()); 2342 ASSERT_TRUE(local.good());
2342 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE)); 2343 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE));
2343 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE)); 2344 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE));
2344 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE)); 2345 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE));
2345 EXPECT_FALSE(server.Get(IS_UNSYNCED)); 2346 EXPECT_FALSE(server.Get(IS_UNSYNCED));
2346 EXPECT_FALSE(local.Get(IS_UNSYNCED)); 2347 EXPECT_FALSE(local.Get(IS_UNSYNCED));
2347 EXPECT_EQ("Bar.htm", server.Get(NON_UNIQUE_NAME)); 2348 EXPECT_EQ("Bar.htm", server.Get(NON_UNIQUE_NAME));
2348 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME)); 2349 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME));
2349 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark. 2350 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark.
2350 server.Get(SPECIFICS).GetExtension(sync_pb::bookmark).url()); 2351 server.Get(SPECIFICS).GetExtension(sync_pb::bookmark).url());
2351 } 2352 }
2352 } 2353 }
2353 2354
2354 // Same as NewEntryAnddServerEntrySharePath, but using the old-style protocol. 2355 // Same as NewEntryAnddServerEntrySharePath, but using the old-style protocol.
2355 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath_OldBookmarksProto) { 2356 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath_OldBookmarksProto) {
2356 mock_server_->set_use_legacy_bookmarks_protocol(true); 2357 mock_server_->set_use_legacy_bookmarks_protocol(true);
2357 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2358 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2358 CHECK(dir.good()); 2359 CHECK(dir.good());
2359 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10); 2360 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10);
2360 SyncShareAsDelegate(); 2361 SyncShareAsDelegate();
2361 int64 local_folder_handle; 2362 int64 local_folder_handle;
2362 syncable::Id local_folder_id; 2363 syncable::Id local_folder_id;
2363 { 2364 {
2364 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 2365 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
2365 MutableEntry new_entry(&wtrans, CREATE, wtrans.root_id(), "Bar.htm"); 2366 MutableEntry new_entry(&wtrans, CREATE, wtrans.root_id(), "Bar.htm");
2366 ASSERT_TRUE(new_entry.good()); 2367 ASSERT_TRUE(new_entry.good());
2367 local_folder_id = new_entry.Get(ID); 2368 local_folder_id = new_entry.Get(ID);
2368 local_folder_handle = new_entry.Get(META_HANDLE); 2369 local_folder_handle = new_entry.Get(META_HANDLE);
2369 new_entry.Put(IS_UNSYNCED, true); 2370 new_entry.Put(IS_UNSYNCED, true);
2370 new_entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2371 new_entry.Put(SPECIFICS, DefaultBookmarkSpecifics());
2371 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2372 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2372 ASSERT_TRUE(old.good()); 2373 ASSERT_TRUE(old.good());
2373 WriteTestDataToEntry(&wtrans, &old); 2374 WriteTestDataToEntry(&wtrans, &old);
2374 } 2375 }
2375 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20); 2376 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20);
2376 mock_server_->set_conflict_all_commits(true); 2377 mock_server_->set_conflict_all_commits(true);
2377 SyncShareAsDelegate(); 2378 SyncShareAsDelegate();
2378 saw_syncer_event_ = false; 2379 saw_syncer_event_ = false;
2379 { 2380 {
2380 // Update #20 should have been dropped in favor of the local version. 2381 // Update #20 should have been dropped in favor of the local version.
2381 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 2382 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
2382 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2383 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2383 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); 2384 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle);
2384 ASSERT_TRUE(server.good()); 2385 ASSERT_TRUE(server.good());
2385 ASSERT_TRUE(local.good()); 2386 ASSERT_TRUE(local.good());
2386 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE)); 2387 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE));
2387 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE)); 2388 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE));
2388 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE)); 2389 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE));
2389 EXPECT_TRUE(server.Get(IS_UNSYNCED)); 2390 EXPECT_TRUE(server.Get(IS_UNSYNCED));
2390 EXPECT_TRUE(local.Get(IS_UNSYNCED)); 2391 EXPECT_TRUE(local.Get(IS_UNSYNCED));
2391 EXPECT_EQ("Foo.htm", server.Get(NON_UNIQUE_NAME)); 2392 EXPECT_EQ("Foo.htm", server.Get(NON_UNIQUE_NAME));
2392 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME)); 2393 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME));
2393 } 2394 }
2394 // Allow local changes to commit. 2395 // Allow local changes to commit.
2395 mock_server_->set_conflict_all_commits(false); 2396 mock_server_->set_conflict_all_commits(false);
2396 SyncShareAsDelegate(); 2397 SyncShareAsDelegate();
2397 saw_syncer_event_ = false; 2398 saw_syncer_event_ = false;
2398 2399
2399 // Now add a server change to make the two names equal. There should 2400 // Now add a server change to make the two names equal. There should
2400 // be no conflict with that, since names are not unique. 2401 // be no conflict with that, since names are not unique.
2401 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30); 2402 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30);
2402 SyncShareAsDelegate(); 2403 SyncShareAsDelegate();
2403 saw_syncer_event_ = false; 2404 saw_syncer_event_ = false;
2404 { 2405 {
2405 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 2406 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
2406 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2407 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2407 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); 2408 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle);
2408 ASSERT_TRUE(server.good()); 2409 ASSERT_TRUE(server.good());
2409 ASSERT_TRUE(local.good()); 2410 ASSERT_TRUE(local.good());
2410 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE)); 2411 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE));
2411 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE)); 2412 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE));
2412 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE)); 2413 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE));
2413 EXPECT_FALSE(server.Get(IS_UNSYNCED)); 2414 EXPECT_FALSE(server.Get(IS_UNSYNCED));
2414 EXPECT_FALSE(local.Get(IS_UNSYNCED)); 2415 EXPECT_FALSE(local.Get(IS_UNSYNCED));
2415 EXPECT_EQ("Bar.htm", server.Get(NON_UNIQUE_NAME)); 2416 EXPECT_EQ("Bar.htm", server.Get(NON_UNIQUE_NAME));
2416 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME)); 2417 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME));
2417 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark. 2418 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark.
2418 server.Get(SPECIFICS).GetExtension(sync_pb::bookmark).url()); 2419 server.Get(SPECIFICS).GetExtension(sync_pb::bookmark).url());
2419 } 2420 }
2420 } 2421 }
2421 2422
2422 2423
2423 // Circular links should be resolved by the server. 2424 // Circular links should be resolved by the server.
2424 TEST_F(SyncerTest, SiblingDirectoriesBecomeCircular) { 2425 TEST_F(SyncerTest, SiblingDirectoriesBecomeCircular) {
2425 // we don't currently resolve this. This test ensures we don't. 2426 // we don't currently resolve this. This test ensures we don't.
2426 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2427 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2427 CHECK(dir.good()); 2428 CHECK(dir.good());
2428 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); 2429 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10);
2429 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); 2430 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10);
2430 SyncShareAsDelegate(); 2431 SyncShareAsDelegate();
2431 { 2432 {
2432 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 2433 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
2433 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2434 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2434 ASSERT_TRUE(A.good()); 2435 ASSERT_TRUE(A.good());
2435 A.Put(IS_UNSYNCED, true); 2436 A.Put(IS_UNSYNCED, true);
2436 ASSERT_TRUE(A.Put(PARENT_ID, ids_.FromNumber(2))); 2437 ASSERT_TRUE(A.Put(PARENT_ID, ids_.FromNumber(2)));
2437 ASSERT_TRUE(A.Put(NON_UNIQUE_NAME, "B")); 2438 ASSERT_TRUE(A.Put(NON_UNIQUE_NAME, "B"));
2438 } 2439 }
2439 mock_server_->AddUpdateDirectory(2, 1, "A", 20, 20); 2440 mock_server_->AddUpdateDirectory(2, 1, "A", 20, 20);
2440 mock_server_->set_conflict_all_commits(true); 2441 mock_server_->set_conflict_all_commits(true);
2441 SyncShareAsDelegate(); 2442 SyncShareAsDelegate();
2442 saw_syncer_event_ = false; 2443 saw_syncer_event_ = false;
2443 { 2444 {
2444 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 2445 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
2445 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2446 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2446 ASSERT_TRUE(A.good()); 2447 ASSERT_TRUE(A.good());
2447 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 2448 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
2448 ASSERT_TRUE(B.good()); 2449 ASSERT_TRUE(B.good());
2449 EXPECT_TRUE(A.Get(NON_UNIQUE_NAME) == "B"); 2450 EXPECT_TRUE(A.Get(NON_UNIQUE_NAME) == "B");
2450 EXPECT_TRUE(B.Get(NON_UNIQUE_NAME) == "B"); 2451 EXPECT_TRUE(B.Get(NON_UNIQUE_NAME) == "B");
2451 } 2452 }
2452 } 2453 }
2453 2454
2454 TEST_F(SyncerTest, ConflictSetClassificationError) { 2455 TEST_F(SyncerTest, ConflictSetClassificationError) {
2455 // This code used to cause a CHECK failure because we incorrectly thought 2456 // This code used to cause a CHECK failure because we incorrectly thought
2456 // a set was only unapplied updates. 2457 // a set was only unapplied updates.
2457 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2458 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2458 CHECK(dir.good()); 2459 CHECK(dir.good());
2459 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); 2460 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10);
2460 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); 2461 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10);
2461 mock_server_->set_conflict_all_commits(true); 2462 mock_server_->set_conflict_all_commits(true);
2462 SyncShareAsDelegate(); 2463 SyncShareAsDelegate();
2463 { 2464 {
2464 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 2465 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
2465 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2466 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2466 ASSERT_TRUE(A.good()); 2467 ASSERT_TRUE(A.good());
2467 A.Put(IS_UNSYNCED, true); 2468 A.Put(IS_UNSYNCED, true);
2468 A.Put(IS_UNAPPLIED_UPDATE, true); 2469 A.Put(IS_UNAPPLIED_UPDATE, true);
2469 A.Put(SERVER_NON_UNIQUE_NAME, "B"); 2470 A.Put(SERVER_NON_UNIQUE_NAME, "B");
2470 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 2471 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
2471 ASSERT_TRUE(B.good()); 2472 ASSERT_TRUE(B.good());
2472 B.Put(IS_UNAPPLIED_UPDATE, true); 2473 B.Put(IS_UNAPPLIED_UPDATE, true);
2473 B.Put(SERVER_NON_UNIQUE_NAME, "A"); 2474 B.Put(SERVER_NON_UNIQUE_NAME, "A");
2474 } 2475 }
2475 SyncShareAsDelegate(); 2476 SyncShareAsDelegate();
2476 saw_syncer_event_ = false; 2477 saw_syncer_event_ = false;
2477 } 2478 }
2478 2479
2479 TEST_F(SyncerTest, SwapEntryNames) { 2480 TEST_F(SyncerTest, SwapEntryNames) {
2480 // Simple transaction test. 2481 // Simple transaction test.
2481 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2482 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2482 CHECK(dir.good()); 2483 CHECK(dir.good());
2483 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); 2484 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10);
2484 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); 2485 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10);
2485 mock_server_->set_conflict_all_commits(true); 2486 mock_server_->set_conflict_all_commits(true);
2486 SyncShareAsDelegate(); 2487 SyncShareAsDelegate();
2487 { 2488 {
2488 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 2489 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
2489 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2490 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2490 ASSERT_TRUE(A.good()); 2491 ASSERT_TRUE(A.good());
2491 A.Put(IS_UNSYNCED, true); 2492 A.Put(IS_UNSYNCED, true);
2492 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 2493 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
2493 ASSERT_TRUE(B.good()); 2494 ASSERT_TRUE(B.good());
2494 B.Put(IS_UNSYNCED, true); 2495 B.Put(IS_UNSYNCED, true);
2495 ASSERT_TRUE(A.Put(NON_UNIQUE_NAME, "C")); 2496 ASSERT_TRUE(A.Put(NON_UNIQUE_NAME, "C"));
2496 ASSERT_TRUE(B.Put(NON_UNIQUE_NAME, "A")); 2497 ASSERT_TRUE(B.Put(NON_UNIQUE_NAME, "A"));
2497 ASSERT_TRUE(A.Put(NON_UNIQUE_NAME, "B")); 2498 ASSERT_TRUE(A.Put(NON_UNIQUE_NAME, "B"));
2498 } 2499 }
2499 SyncShareAsDelegate(); 2500 SyncShareAsDelegate();
2500 saw_syncer_event_ = false; 2501 saw_syncer_event_ = false;
2501 } 2502 }
2502 2503
2503 TEST_F(SyncerTest, DualDeletionWithNewItemNameClash) { 2504 TEST_F(SyncerTest, DualDeletionWithNewItemNameClash) {
2504 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2505 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2505 CHECK(dir.good()); 2506 CHECK(dir.good());
2506 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); 2507 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10);
2507 mock_server_->AddUpdateBookmark(2, 0, "B", 10, 10); 2508 mock_server_->AddUpdateBookmark(2, 0, "B", 10, 10);
2508 mock_server_->set_conflict_all_commits(true); 2509 mock_server_->set_conflict_all_commits(true);
2509 SyncShareAsDelegate(); 2510 SyncShareAsDelegate();
2510 { 2511 {
2511 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2512 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2512 MutableEntry B(&trans, GET_BY_ID, ids_.FromNumber(2)); 2513 MutableEntry B(&trans, GET_BY_ID, ids_.FromNumber(2));
2513 ASSERT_TRUE(B.good()); 2514 ASSERT_TRUE(B.good());
2514 WriteTestDataToEntry(&trans, &B); 2515 WriteTestDataToEntry(&trans, &B);
2515 B.Put(IS_DEL, true); 2516 B.Put(IS_DEL, true);
2516 } 2517 }
2517 mock_server_->AddUpdateBookmark(2, 0, "A", 11, 11); 2518 mock_server_->AddUpdateBookmark(2, 0, "A", 11, 11);
2518 mock_server_->SetLastUpdateDeleted(); 2519 mock_server_->SetLastUpdateDeleted();
2519 SyncShareAsDelegate(); 2520 SyncShareAsDelegate();
2520 { 2521 {
2521 ReadTransaction trans(dir, __FILE__, __LINE__); 2522 ReadTransaction trans(dir, FROM_HERE);
2522 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2)); 2523 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2));
2523 ASSERT_TRUE(B.good()); 2524 ASSERT_TRUE(B.good());
2524 EXPECT_FALSE(B.Get(IS_UNSYNCED)); 2525 EXPECT_FALSE(B.Get(IS_UNSYNCED));
2525 EXPECT_FALSE(B.Get(IS_UNAPPLIED_UPDATE)); 2526 EXPECT_FALSE(B.Get(IS_UNAPPLIED_UPDATE));
2526 } 2527 }
2527 saw_syncer_event_ = false; 2528 saw_syncer_event_ = false;
2528 } 2529 }
2529 2530
2530 TEST_F(SyncerTest, FixDirectoryLoopConflict) { 2531 TEST_F(SyncerTest, FixDirectoryLoopConflict) {
2531 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2532 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2532 CHECK(dir.good()); 2533 CHECK(dir.good());
2533 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); 2534 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10);
2534 mock_server_->AddUpdateDirectory(2, 0, "fred", 1, 10); 2535 mock_server_->AddUpdateDirectory(2, 0, "fred", 1, 10);
2535 SyncShareAsDelegate(); 2536 SyncShareAsDelegate();
2536 { 2537 {
2537 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2538 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2538 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 2539 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
2539 ASSERT_TRUE(bob.good()); 2540 ASSERT_TRUE(bob.good());
2540 bob.Put(IS_UNSYNCED, true); 2541 bob.Put(IS_UNSYNCED, true);
2541 bob.Put(PARENT_ID, ids_.FromNumber(2)); 2542 bob.Put(PARENT_ID, ids_.FromNumber(2));
2542 } 2543 }
2543 mock_server_->AddUpdateDirectory(2, 1, "fred", 2, 20); 2544 mock_server_->AddUpdateDirectory(2, 1, "fred", 2, 20);
2544 mock_server_->set_conflict_all_commits(true); 2545 mock_server_->set_conflict_all_commits(true);
2545 SyncShareAsDelegate(); 2546 SyncShareAsDelegate();
2546 SyncShareAsDelegate(); 2547 SyncShareAsDelegate();
2547 { 2548 {
2548 ReadTransaction trans(dir, __FILE__, __LINE__); 2549 ReadTransaction trans(dir, FROM_HERE);
2549 Entry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 2550 Entry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
2550 ASSERT_TRUE(bob.good()); 2551 ASSERT_TRUE(bob.good());
2551 Entry fred(&trans, GET_BY_ID, ids_.FromNumber(2)); 2552 Entry fred(&trans, GET_BY_ID, ids_.FromNumber(2));
2552 ASSERT_TRUE(fred.good()); 2553 ASSERT_TRUE(fred.good());
2553 EXPECT_TRUE(fred.Get(IS_UNSYNCED)); 2554 EXPECT_TRUE(fred.Get(IS_UNSYNCED));
2554 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); 2555 EXPECT_TRUE(bob.Get(IS_UNSYNCED));
2555 EXPECT_FALSE(fred.Get(IS_UNAPPLIED_UPDATE)); 2556 EXPECT_FALSE(fred.Get(IS_UNAPPLIED_UPDATE));
2556 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); 2557 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE));
2557 } 2558 }
2558 saw_syncer_event_ = false; 2559 saw_syncer_event_ = false;
2559 } 2560 }
2560 2561
2561 TEST_F(SyncerTest, ResolveWeWroteTheyDeleted) { 2562 TEST_F(SyncerTest, ResolveWeWroteTheyDeleted) {
2562 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2563 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2563 CHECK(dir.good()); 2564 CHECK(dir.good());
2564 2565
2565 int64 bob_metahandle; 2566 int64 bob_metahandle;
2566 2567
2567 mock_server_->AddUpdateBookmark(1, 0, "bob", 1, 10); 2568 mock_server_->AddUpdateBookmark(1, 0, "bob", 1, 10);
2568 SyncShareAsDelegate(); 2569 SyncShareAsDelegate();
2569 { 2570 {
2570 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2571 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2571 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 2572 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
2572 ASSERT_TRUE(bob.good()); 2573 ASSERT_TRUE(bob.good());
2573 bob_metahandle = bob.Get(META_HANDLE); 2574 bob_metahandle = bob.Get(META_HANDLE);
2574 WriteTestDataToEntry(&trans, &bob); 2575 WriteTestDataToEntry(&trans, &bob);
2575 } 2576 }
2576 mock_server_->AddUpdateBookmark(1, 0, "bob", 2, 10); 2577 mock_server_->AddUpdateBookmark(1, 0, "bob", 2, 10);
2577 mock_server_->SetLastUpdateDeleted(); 2578 mock_server_->SetLastUpdateDeleted();
2578 mock_server_->set_conflict_all_commits(true); 2579 mock_server_->set_conflict_all_commits(true);
2579 SyncShareAsDelegate(); 2580 SyncShareAsDelegate();
2580 SyncShareAsDelegate(); 2581 SyncShareAsDelegate();
2581 { 2582 {
2582 ReadTransaction trans(dir, __FILE__, __LINE__); 2583 ReadTransaction trans(dir, FROM_HERE);
2583 Entry bob(&trans, GET_BY_HANDLE, bob_metahandle); 2584 Entry bob(&trans, GET_BY_HANDLE, bob_metahandle);
2584 ASSERT_TRUE(bob.good()); 2585 ASSERT_TRUE(bob.good());
2585 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); 2586 EXPECT_TRUE(bob.Get(IS_UNSYNCED));
2586 EXPECT_FALSE(bob.Get(ID).ServerKnows()); 2587 EXPECT_FALSE(bob.Get(ID).ServerKnows());
2587 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); 2588 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE));
2588 EXPECT_FALSE(bob.Get(IS_DEL)); 2589 EXPECT_FALSE(bob.Get(IS_DEL));
2589 } 2590 }
2590 saw_syncer_event_ = false; 2591 saw_syncer_event_ = false;
2591 } 2592 }
2592 2593
2593 TEST_F(SyncerTest, ServerDeletingFolderWeHaveMovedSomethingInto) { 2594 TEST_F(SyncerTest, ServerDeletingFolderWeHaveMovedSomethingInto) {
2594 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2595 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2595 CHECK(dir.good()); 2596 CHECK(dir.good());
2596 2597
2597 syncable::Id bob_id = ids_.NewServerId(); 2598 syncable::Id bob_id = ids_.NewServerId();
2598 syncable::Id fred_id = ids_.NewServerId(); 2599 syncable::Id fred_id = ids_.NewServerId();
2599 2600
2600 mock_server_->AddUpdateDirectory(bob_id, TestIdFactory::root(), 2601 mock_server_->AddUpdateDirectory(bob_id, TestIdFactory::root(),
2601 "bob", 1, 10); 2602 "bob", 1, 10);
2602 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(), 2603 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(),
2603 "fred", 1, 10); 2604 "fred", 1, 10);
2604 SyncShareAsDelegate(); 2605 SyncShareAsDelegate();
2605 { 2606 {
2606 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2607 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2607 MutableEntry bob(&trans, GET_BY_ID, bob_id); 2608 MutableEntry bob(&trans, GET_BY_ID, bob_id);
2608 ASSERT_TRUE(bob.good()); 2609 ASSERT_TRUE(bob.good());
2609 bob.Put(IS_UNSYNCED, true); 2610 bob.Put(IS_UNSYNCED, true);
2610 bob.Put(PARENT_ID, fred_id); 2611 bob.Put(PARENT_ID, fred_id);
2611 } 2612 }
2612 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(), 2613 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(),
2613 "fred", 2, 20); 2614 "fred", 2, 20);
2614 mock_server_->SetLastUpdateDeleted(); 2615 mock_server_->SetLastUpdateDeleted();
2615 mock_server_->set_conflict_all_commits(true); 2616 mock_server_->set_conflict_all_commits(true);
2616 SyncShareAsDelegate(); 2617 SyncShareAsDelegate();
2617 SyncShareAsDelegate(); 2618 SyncShareAsDelegate();
2618 { 2619 {
2619 ReadTransaction trans(dir, __FILE__, __LINE__); 2620 ReadTransaction trans(dir, FROM_HERE);
2620 2621
2621 Entry bob(&trans, GET_BY_ID, bob_id); 2622 Entry bob(&trans, GET_BY_ID, bob_id);
2622 ASSERT_TRUE(bob.good()); 2623 ASSERT_TRUE(bob.good());
2623 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); 2624 EXPECT_TRUE(bob.Get(IS_UNSYNCED));
2624 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); 2625 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE));
2625 EXPECT_TRUE(bob.Get(NON_UNIQUE_NAME) == "bob"); 2626 EXPECT_TRUE(bob.Get(NON_UNIQUE_NAME) == "bob");
2626 EXPECT_NE(bob.Get(PARENT_ID), fred_id); 2627 EXPECT_NE(bob.Get(PARENT_ID), fred_id);
2627 2628
2628 // Entry was deleted and reborn. 2629 // Entry was deleted and reborn.
2629 Entry dead_fred(&trans, GET_BY_ID, fred_id); 2630 Entry dead_fred(&trans, GET_BY_ID, fred_id);
(...skipping 15 matching lines...) Expand all
2645 // TODO(chron): The fourth time that SyncShare is called it crashes. 2646 // TODO(chron): The fourth time that SyncShare is called it crashes.
2646 // This seems to be due to a bug in the conflict set building logic. 2647 // This seems to be due to a bug in the conflict set building logic.
2647 // http://crbug.com/46621 2648 // http://crbug.com/46621
2648 TEST_F(SyncerTest, DISABLED_ServerDeletingFolderWeHaveAnOpenEntryIn) { 2649 TEST_F(SyncerTest, DISABLED_ServerDeletingFolderWeHaveAnOpenEntryIn) {
2649 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2650 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2650 CHECK(dir.good()); 2651 CHECK(dir.good());
2651 mock_server_->AddUpdateBookmark(1, 0, "bob", 1, 10); 2652 mock_server_->AddUpdateBookmark(1, 0, "bob", 1, 10);
2652 mock_server_->AddUpdateDirectory(2, 0, "fred", 1, 10); 2653 mock_server_->AddUpdateDirectory(2, 0, "fred", 1, 10);
2653 SyncShareAsDelegate(); 2654 SyncShareAsDelegate();
2654 { 2655 {
2655 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2656 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2656 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 2657 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
2657 ASSERT_TRUE(bob.good()); 2658 ASSERT_TRUE(bob.good());
2658 bob.Put(IS_UNSYNCED, true); 2659 bob.Put(IS_UNSYNCED, true);
2659 WriteTestDataToEntry(&trans, &bob); 2660 WriteTestDataToEntry(&trans, &bob);
2660 } 2661 }
2661 SyncShareAsDelegate(); 2662 SyncShareAsDelegate();
2662 { 2663 {
2663 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2664 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2664 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 2665 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
2665 ASSERT_TRUE(bob.good()); 2666 ASSERT_TRUE(bob.good());
2666 EXPECT_FALSE(bob.Get(IS_UNSYNCED)); 2667 EXPECT_FALSE(bob.Get(IS_UNSYNCED));
2667 bob.Put(IS_UNSYNCED, true); 2668 bob.Put(IS_UNSYNCED, true);
2668 bob.Put(PARENT_ID, ids_.FromNumber(2)); 2669 bob.Put(PARENT_ID, ids_.FromNumber(2));
2669 } 2670 }
2670 mock_server_->AddUpdateDirectory(2, 0, "fred", 2, 20); 2671 mock_server_->AddUpdateDirectory(2, 0, "fred", 2, 20);
2671 mock_server_->SetLastUpdateDeleted(); 2672 mock_server_->SetLastUpdateDeleted();
2672 mock_server_->set_conflict_all_commits(true); 2673 mock_server_->set_conflict_all_commits(true);
2673 saw_syncer_event_ = false; 2674 saw_syncer_event_ = false;
2674 // These SyncShares would cause a CHECK because we'd think we were stuck. 2675 // These SyncShares would cause a CHECK because we'd think we were stuck.
2675 SyncShareAsDelegate(); 2676 SyncShareAsDelegate();
2676 SyncShareAsDelegate(); 2677 SyncShareAsDelegate();
2677 SyncShareAsDelegate(); 2678 SyncShareAsDelegate();
2678 SyncShareAsDelegate(); 2679 SyncShareAsDelegate();
2679 SyncShareAsDelegate(); 2680 SyncShareAsDelegate();
2680 SyncShareAsDelegate(); 2681 SyncShareAsDelegate();
2681 SyncShareAsDelegate(); 2682 SyncShareAsDelegate();
2682 SyncShareAsDelegate(); 2683 SyncShareAsDelegate();
2683 EXPECT_FALSE(saw_syncer_event_); 2684 EXPECT_FALSE(saw_syncer_event_);
2684 { 2685 {
2685 ReadTransaction trans(dir, __FILE__, __LINE__); 2686 ReadTransaction trans(dir, FROM_HERE);
2686 Entry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 2687 Entry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
2687 ASSERT_TRUE(bob.good()); 2688 ASSERT_TRUE(bob.good());
2688 Id fred_id = 2689 Id fred_id =
2689 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "fred"); 2690 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "fred");
2690 Entry fred(&trans, GET_BY_ID, fred_id); 2691 Entry fred(&trans, GET_BY_ID, fred_id);
2691 ASSERT_TRUE(fred.good()); 2692 ASSERT_TRUE(fred.good());
2692 EXPECT_FALSE(fred.Get(IS_UNSYNCED)); 2693 EXPECT_FALSE(fred.Get(IS_UNSYNCED));
2693 EXPECT_TRUE(fred.Get(IS_UNAPPLIED_UPDATE)); 2694 EXPECT_TRUE(fred.Get(IS_UNAPPLIED_UPDATE));
2694 EXPECT_TRUE(bob.Get(PARENT_ID) == fred.Get(ID)); 2695 EXPECT_TRUE(bob.Get(PARENT_ID) == fred.Get(ID));
2695 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); 2696 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE));
2696 } 2697 }
2697 saw_syncer_event_ = false; 2698 saw_syncer_event_ = false;
2698 } 2699 }
2699 2700
2700 TEST_F(SyncerTest, WeMovedSomethingIntoAFolderServerHasDeleted) { 2701 TEST_F(SyncerTest, WeMovedSomethingIntoAFolderServerHasDeleted) {
2701 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2702 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2702 CHECK(dir.good()); 2703 CHECK(dir.good());
2703 2704
2704 syncable::Id bob_id = ids_.NewServerId(); 2705 syncable::Id bob_id = ids_.NewServerId();
2705 syncable::Id fred_id = ids_.NewServerId(); 2706 syncable::Id fred_id = ids_.NewServerId();
2706 2707
2707 mock_server_->AddUpdateDirectory(bob_id, TestIdFactory::root(), 2708 mock_server_->AddUpdateDirectory(bob_id, TestIdFactory::root(),
2708 "bob", 1, 10); 2709 "bob", 1, 10);
2709 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(), 2710 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(),
2710 "fred", 1, 10); 2711 "fred", 1, 10);
2711 SyncShareAsDelegate(); 2712 SyncShareAsDelegate();
2712 { 2713 {
2713 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2714 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2714 Entry fred(&trans, GET_BY_ID, fred_id); 2715 Entry fred(&trans, GET_BY_ID, fred_id);
2715 ASSERT_TRUE(fred.good()); 2716 ASSERT_TRUE(fred.good());
2716 2717
2717 MutableEntry bob(&trans, GET_BY_ID, bob_id); 2718 MutableEntry bob(&trans, GET_BY_ID, bob_id);
2718 ASSERT_TRUE(bob.good()); 2719 ASSERT_TRUE(bob.good());
2719 bob.Put(IS_UNSYNCED, true); 2720 bob.Put(IS_UNSYNCED, true);
2720 bob.Put(PARENT_ID, fred_id); 2721 bob.Put(PARENT_ID, fred_id);
2721 } 2722 }
2722 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(), 2723 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(),
2723 "fred", 2, 20); 2724 "fred", 2, 20);
2724 mock_server_->SetLastUpdateDeleted(); 2725 mock_server_->SetLastUpdateDeleted();
2725 mock_server_->set_conflict_all_commits(true); 2726 mock_server_->set_conflict_all_commits(true);
2726 SyncShareAsDelegate(); 2727 SyncShareAsDelegate();
2727 SyncShareAsDelegate(); 2728 SyncShareAsDelegate();
2728 { 2729 {
2729 ReadTransaction trans(dir, __FILE__, __LINE__); 2730 ReadTransaction trans(dir, FROM_HERE);
2730 Entry bob(&trans, GET_BY_ID, bob_id); 2731 Entry bob(&trans, GET_BY_ID, bob_id);
2731 ASSERT_TRUE(bob.good()); 2732 ASSERT_TRUE(bob.good());
2732 2733
2733 // Entry was deleted by server. We'll make a new one though with a new ID. 2734 // Entry was deleted by server. We'll make a new one though with a new ID.
2734 Entry dead_fred(&trans, GET_BY_ID, fred_id); 2735 Entry dead_fred(&trans, GET_BY_ID, fred_id);
2735 EXPECT_FALSE(dead_fred.good()); 2736 EXPECT_FALSE(dead_fred.good());
2736 2737
2737 // Fred is reborn with a local ID. 2738 // Fred is reborn with a local ID.
2738 Entry fred(&trans, GET_BY_ID, bob.Get(PARENT_ID)); 2739 Entry fred(&trans, GET_BY_ID, bob.Get(PARENT_ID));
2739 EXPECT_EQ("fred", fred.Get(NON_UNIQUE_NAME)); 2740 EXPECT_EQ("fred", fred.Get(NON_UNIQUE_NAME));
(...skipping 23 matching lines...) Expand all
2763 MoveBobIntoID2(); 2764 MoveBobIntoID2();
2764 done_ = true; 2765 done_ = true;
2765 } 2766 }
2766 } 2767 }
2767 2768
2768 protected: 2769 protected:
2769 void MoveBobIntoID2() { 2770 void MoveBobIntoID2() {
2770 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2771 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2771 CHECK(dir.good()); 2772 CHECK(dir.good());
2772 2773
2773 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2774 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2774 Entry alice(&trans, GET_BY_ID, 2775 Entry alice(&trans, GET_BY_ID,
2775 TestIdFactory::FromNumber(fred_id_number)); 2776 TestIdFactory::FromNumber(fred_id_number));
2776 CHECK(alice.good()); 2777 CHECK(alice.good());
2777 EXPECT_TRUE(!alice.Get(IS_DEL)); 2778 EXPECT_TRUE(!alice.Get(IS_DEL));
2778 EXPECT_TRUE(alice.Get(SYNCING)) << "Expected to be called mid-commit."; 2779 EXPECT_TRUE(alice.Get(SYNCING)) << "Expected to be called mid-commit.";
2779 MutableEntry bob(&trans, GET_BY_ID, 2780 MutableEntry bob(&trans, GET_BY_ID,
2780 TestIdFactory::FromNumber(bob_id_number)); 2781 TestIdFactory::FromNumber(bob_id_number));
2781 CHECK(bob.good()); 2782 CHECK(bob.good());
2782 bob.Put(IS_UNSYNCED, true); 2783 bob.Put(IS_UNSYNCED, true);
2783 2784
(...skipping 13 matching lines...) Expand all
2797 FolderMoveDeleteRenameTest::bob_id_number); 2798 FolderMoveDeleteRenameTest::bob_id_number);
2798 const syncable::Id fred_id = TestIdFactory::FromNumber( 2799 const syncable::Id fred_id = TestIdFactory::FromNumber(
2799 FolderMoveDeleteRenameTest::fred_id_number); 2800 FolderMoveDeleteRenameTest::fred_id_number);
2800 2801
2801 mock_server_->AddUpdateDirectory(bob_id, TestIdFactory::root(), 2802 mock_server_->AddUpdateDirectory(bob_id, TestIdFactory::root(),
2802 "bob", 1, 10); 2803 "bob", 1, 10);
2803 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(), 2804 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(),
2804 "fred", 1, 10); 2805 "fred", 1, 10);
2805 SyncShareAsDelegate(); 2806 SyncShareAsDelegate();
2806 { 2807 {
2807 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2808 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2808 MutableEntry fred(&trans, GET_BY_ID, fred_id); 2809 MutableEntry fred(&trans, GET_BY_ID, fred_id);
2809 ASSERT_TRUE(fred.good()); 2810 ASSERT_TRUE(fred.good());
2810 fred.Put(IS_UNSYNCED, true); 2811 fred.Put(IS_UNSYNCED, true);
2811 fred.Put(SYNCING, false); 2812 fred.Put(SYNCING, false);
2812 fred.Put(NON_UNIQUE_NAME, "Alice"); 2813 fred.Put(NON_UNIQUE_NAME, "Alice");
2813 } 2814 }
2814 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(), 2815 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(),
2815 "fred", 2, 20); 2816 "fred", 2, 20);
2816 mock_server_->SetLastUpdateDeleted(); 2817 mock_server_->SetLastUpdateDeleted();
2817 mock_server_->set_conflict_all_commits(true); 2818 mock_server_->set_conflict_all_commits(true);
2818 // This test is a little brittle. We want to move the item into the folder 2819 // This test is a little brittle. We want to move the item into the folder
2819 // such that we think we're dealing with a simple conflict, but in reality 2820 // such that we think we're dealing with a simple conflict, but in reality
2820 // it's actually a conflict set. 2821 // it's actually a conflict set.
2821 mock_server_->SetMidCommitCallback( 2822 mock_server_->SetMidCommitCallback(
2822 NewCallback<FolderMoveDeleteRenameTest>(this, 2823 NewCallback<FolderMoveDeleteRenameTest>(this,
2823 &FolderMoveDeleteRenameTest::MoveBobIntoID2Runner)); 2824 &FolderMoveDeleteRenameTest::MoveBobIntoID2Runner));
2824 SyncShareAsDelegate(); 2825 SyncShareAsDelegate();
2825 SyncShareAsDelegate(); 2826 SyncShareAsDelegate();
2826 SyncShareAsDelegate(); 2827 SyncShareAsDelegate();
2827 { 2828 {
2828 ReadTransaction trans(dir, __FILE__, __LINE__); 2829 ReadTransaction trans(dir, FROM_HERE);
2829 Entry bob(&trans, GET_BY_ID, bob_id); 2830 Entry bob(&trans, GET_BY_ID, bob_id);
2830 ASSERT_TRUE(bob.good()); 2831 ASSERT_TRUE(bob.good());
2831 2832
2832 // Old entry is dead 2833 // Old entry is dead
2833 Entry dead_fred(&trans, GET_BY_ID, fred_id); 2834 Entry dead_fred(&trans, GET_BY_ID, fred_id);
2834 EXPECT_FALSE(dead_fred.good()); 2835 EXPECT_FALSE(dead_fred.good());
2835 2836
2836 // New ID is created to fill parent folder, named correctly 2837 // New ID is created to fill parent folder, named correctly
2837 Entry alice(&trans, GET_BY_ID, bob.Get(PARENT_ID)); 2838 Entry alice(&trans, GET_BY_ID, bob.Get(PARENT_ID));
2838 ASSERT_TRUE(alice.good()); 2839 ASSERT_TRUE(alice.good());
(...skipping 18 matching lines...) Expand all
2857 syncable::Id bob_id = ids_.NewServerId(); 2858 syncable::Id bob_id = ids_.NewServerId();
2858 syncable::Id fred_id = ids_.NewServerId(); 2859 syncable::Id fred_id = ids_.NewServerId();
2859 2860
2860 mock_server_->AddUpdateDirectory(bob_id, TestIdFactory::root(), 2861 mock_server_->AddUpdateDirectory(bob_id, TestIdFactory::root(),
2861 "bob", 1, 10); 2862 "bob", 1, 10);
2862 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(), 2863 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(),
2863 "fred", 1, 10); 2864 "fred", 1, 10);
2864 SyncShareAsDelegate(); 2865 SyncShareAsDelegate();
2865 syncable::Id new_item_id; 2866 syncable::Id new_item_id;
2866 { 2867 {
2867 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2868 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2868 MutableEntry bob(&trans, GET_BY_ID, bob_id); 2869 MutableEntry bob(&trans, GET_BY_ID, bob_id);
2869 ASSERT_TRUE(bob.good()); 2870 ASSERT_TRUE(bob.good());
2870 bob.Put(IS_UNSYNCED, true); 2871 bob.Put(IS_UNSYNCED, true);
2871 bob.Put(PARENT_ID, fred_id); 2872 bob.Put(PARENT_ID, fred_id);
2872 MutableEntry new_item(&trans, CREATE, fred_id, "new_item"); 2873 MutableEntry new_item(&trans, CREATE, fred_id, "new_item");
2873 WriteTestDataToEntry(&trans, &new_item); 2874 WriteTestDataToEntry(&trans, &new_item);
2874 new_item_id = new_item.Get(ID); 2875 new_item_id = new_item.Get(ID);
2875 } 2876 }
2876 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(), 2877 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(),
2877 "fred", 2, 20); 2878 "fred", 2, 20);
2878 mock_server_->SetLastUpdateDeleted(); 2879 mock_server_->SetLastUpdateDeleted();
2879 mock_server_->set_conflict_all_commits(true); 2880 mock_server_->set_conflict_all_commits(true);
2880 SyncShareAsDelegate(); 2881 SyncShareAsDelegate();
2881 SyncShareAsDelegate(); 2882 SyncShareAsDelegate();
2882 { 2883 {
2883 ReadTransaction trans(dir, __FILE__, __LINE__); 2884 ReadTransaction trans(dir, FROM_HERE);
2884 2885
2885 Entry bob(&trans, GET_BY_ID, bob_id); 2886 Entry bob(&trans, GET_BY_ID, bob_id);
2886 ASSERT_TRUE(bob.good()); 2887 ASSERT_TRUE(bob.good());
2887 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); 2888 EXPECT_TRUE(bob.Get(IS_UNSYNCED));
2888 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); 2889 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE));
2889 EXPECT_NE(bob.Get(PARENT_ID), fred_id); 2890 EXPECT_NE(bob.Get(PARENT_ID), fred_id);
2890 2891
2891 // Was recreated. Old one shouldn't exist. 2892 // Was recreated. Old one shouldn't exist.
2892 Entry dead_fred(&trans, GET_BY_ID, fred_id); 2893 Entry dead_fred(&trans, GET_BY_ID, fred_id);
2893 EXPECT_FALSE(dead_fred.good()); 2894 EXPECT_FALSE(dead_fred.good());
(...skipping 13 matching lines...) Expand all
2907 saw_syncer_event_ = false; 2908 saw_syncer_event_ = false;
2908 } 2909 }
2909 2910
2910 TEST_F(SyncerTest, ServerMovedSomethingIntoAFolderWeHaveDeleted) { 2911 TEST_F(SyncerTest, ServerMovedSomethingIntoAFolderWeHaveDeleted) {
2911 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2912 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2912 CHECK(dir.good()); 2913 CHECK(dir.good());
2913 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); 2914 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10);
2914 mock_server_->AddUpdateDirectory(2, 0, "fred", 1, 10); 2915 mock_server_->AddUpdateDirectory(2, 0, "fred", 1, 10);
2915 LoopSyncShare(); 2916 LoopSyncShare();
2916 { 2917 {
2917 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2918 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2918 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 2919 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
2919 ASSERT_TRUE(bob.good()); 2920 ASSERT_TRUE(bob.good());
2920 bob.Put(IS_UNSYNCED, true); 2921 bob.Put(IS_UNSYNCED, true);
2921 bob.Put(IS_DEL, true); 2922 bob.Put(IS_DEL, true);
2922 } 2923 }
2923 mock_server_->AddUpdateDirectory(2, 1, "fred", 2, 20); 2924 mock_server_->AddUpdateDirectory(2, 1, "fred", 2, 20);
2924 mock_server_->set_conflict_all_commits(true); 2925 mock_server_->set_conflict_all_commits(true);
2925 LoopSyncShare(); 2926 LoopSyncShare();
2926 LoopSyncShare(); 2927 LoopSyncShare();
2927 { 2928 {
2928 ReadTransaction trans(dir, __FILE__, __LINE__); 2929 ReadTransaction trans(dir, FROM_HERE);
2929 Entry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 2930 Entry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
2930 ASSERT_TRUE(bob.good()); 2931 ASSERT_TRUE(bob.good());
2931 Entry fred(&trans, GET_BY_ID, ids_.FromNumber(2)); 2932 Entry fred(&trans, GET_BY_ID, ids_.FromNumber(2));
2932 ASSERT_TRUE(fred.good()); 2933 ASSERT_TRUE(fred.good());
2933 EXPECT_FALSE(fred.Get(IS_UNSYNCED)); 2934 EXPECT_FALSE(fred.Get(IS_UNSYNCED));
2934 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); 2935 EXPECT_TRUE(bob.Get(IS_UNSYNCED));
2935 EXPECT_TRUE(fred.Get(PARENT_ID) == bob.Get(ID)); 2936 EXPECT_TRUE(fred.Get(PARENT_ID) == bob.Get(ID));
2936 EXPECT_TRUE(bob.Get(PARENT_ID) == root_id_); 2937 EXPECT_TRUE(bob.Get(PARENT_ID) == root_id_);
2937 EXPECT_FALSE(fred.Get(IS_UNAPPLIED_UPDATE)); 2938 EXPECT_FALSE(fred.Get(IS_UNAPPLIED_UPDATE));
2938 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); 2939 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE));
2939 } 2940 }
2940 saw_syncer_event_ = false; 2941 saw_syncer_event_ = false;
2941 } 2942 }
2942 2943
2943 TEST_F(SyncerTest, ServerMovedAFolderIntoAFolderWeHaveDeletedAndMovedIntoIt) { 2944 TEST_F(SyncerTest, ServerMovedAFolderIntoAFolderWeHaveDeletedAndMovedIntoIt) {
2944 // This test combines circular folders and deleted parents. 2945 // This test combines circular folders and deleted parents.
2945 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2946 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2946 CHECK(dir.good()); 2947 CHECK(dir.good());
2947 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); 2948 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10);
2948 mock_server_->AddUpdateDirectory(2, 0, "fred", 1, 10); 2949 mock_server_->AddUpdateDirectory(2, 0, "fred", 1, 10);
2949 SyncShareAsDelegate(); 2950 SyncShareAsDelegate();
2950 { 2951 {
2951 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2952 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2952 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 2953 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
2953 ASSERT_TRUE(bob.good()); 2954 ASSERT_TRUE(bob.good());
2954 bob.Put(IS_UNSYNCED, true); 2955 bob.Put(IS_UNSYNCED, true);
2955 bob.Put(IS_DEL, true); 2956 bob.Put(IS_DEL, true);
2956 bob.Put(PARENT_ID, ids_.FromNumber(2)); 2957 bob.Put(PARENT_ID, ids_.FromNumber(2));
2957 } 2958 }
2958 mock_server_->AddUpdateDirectory(2, 1, "fred", 2, 20); 2959 mock_server_->AddUpdateDirectory(2, 1, "fred", 2, 20);
2959 mock_server_->set_conflict_all_commits(true); 2960 mock_server_->set_conflict_all_commits(true);
2960 SyncShareAsDelegate(); 2961 SyncShareAsDelegate();
2961 SyncShareAsDelegate(); 2962 SyncShareAsDelegate();
2962 { 2963 {
2963 ReadTransaction trans(dir, __FILE__, __LINE__); 2964 ReadTransaction trans(dir, FROM_HERE);
2964 Entry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 2965 Entry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
2965 ASSERT_TRUE(bob.good()); 2966 ASSERT_TRUE(bob.good());
2966 Entry fred(&trans, GET_BY_ID, ids_.FromNumber(2)); 2967 Entry fred(&trans, GET_BY_ID, ids_.FromNumber(2));
2967 ASSERT_TRUE(fred.good()); 2968 ASSERT_TRUE(fred.good());
2968 EXPECT_TRUE(fred.Get(IS_UNSYNCED)); 2969 EXPECT_TRUE(fred.Get(IS_UNSYNCED));
2969 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); 2970 EXPECT_TRUE(bob.Get(IS_UNSYNCED));
2970 EXPECT_TRUE(bob.Get(IS_DEL)); 2971 EXPECT_TRUE(bob.Get(IS_DEL));
2971 EXPECT_TRUE(fred.Get(PARENT_ID) == root_id_); 2972 EXPECT_TRUE(fred.Get(PARENT_ID) == root_id_);
2972 EXPECT_TRUE(bob.Get(PARENT_ID) == fred.Get(ID)); 2973 EXPECT_TRUE(bob.Get(PARENT_ID) == fred.Get(ID));
2973 EXPECT_FALSE(fred.Get(IS_UNAPPLIED_UPDATE)); 2974 EXPECT_FALSE(fred.Get(IS_UNAPPLIED_UPDATE));
2974 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); 2975 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE));
2975 } 2976 }
2976 saw_syncer_event_ = false; 2977 saw_syncer_event_ = false;
2977 } 2978 }
2978 2979
2979 TEST_F(SyncerTest, NewServerItemInAFolderWeHaveDeleted) { 2980 TEST_F(SyncerTest, NewServerItemInAFolderWeHaveDeleted) {
2980 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 2981 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
2981 CHECK(dir.good()); 2982 CHECK(dir.good());
2982 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); 2983 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10);
2983 LoopSyncShare(); 2984 LoopSyncShare();
2984 { 2985 {
2985 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 2986 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
2986 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 2987 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
2987 ASSERT_TRUE(bob.good()); 2988 ASSERT_TRUE(bob.good());
2988 bob.Put(IS_UNSYNCED, true); 2989 bob.Put(IS_UNSYNCED, true);
2989 bob.Put(IS_DEL, true); 2990 bob.Put(IS_DEL, true);
2990 } 2991 }
2991 mock_server_->AddUpdateDirectory(2, 1, "fred", 2, 20); 2992 mock_server_->AddUpdateDirectory(2, 1, "fred", 2, 20);
2992 mock_server_->set_conflict_all_commits(true); 2993 mock_server_->set_conflict_all_commits(true);
2993 LoopSyncShare(); 2994 LoopSyncShare();
2994 LoopSyncShare(); 2995 LoopSyncShare();
2995 { 2996 {
2996 ReadTransaction trans(dir, __FILE__, __LINE__); 2997 ReadTransaction trans(dir, FROM_HERE);
2997 Entry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 2998 Entry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
2998 ASSERT_TRUE(bob.good()); 2999 ASSERT_TRUE(bob.good());
2999 Entry fred(&trans, GET_BY_ID, ids_.FromNumber(2)); 3000 Entry fred(&trans, GET_BY_ID, ids_.FromNumber(2));
3000 ASSERT_TRUE(fred.good()); 3001 ASSERT_TRUE(fred.good());
3001 EXPECT_FALSE(fred.Get(IS_UNSYNCED)); 3002 EXPECT_FALSE(fred.Get(IS_UNSYNCED));
3002 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); 3003 EXPECT_TRUE(bob.Get(IS_UNSYNCED));
3003 EXPECT_TRUE(fred.Get(PARENT_ID) == bob.Get(ID)); 3004 EXPECT_TRUE(fred.Get(PARENT_ID) == bob.Get(ID));
3004 EXPECT_TRUE(bob.Get(PARENT_ID) == root_id_); 3005 EXPECT_TRUE(bob.Get(PARENT_ID) == root_id_);
3005 EXPECT_FALSE(fred.Get(IS_UNAPPLIED_UPDATE)); 3006 EXPECT_FALSE(fred.Get(IS_UNAPPLIED_UPDATE));
3006 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); 3007 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE));
3007 } 3008 }
3008 saw_syncer_event_ = false; 3009 saw_syncer_event_ = false;
3009 } 3010 }
3010 3011
3011 TEST_F(SyncerTest, NewServerItemInAFolderHierarchyWeHaveDeleted) { 3012 TEST_F(SyncerTest, NewServerItemInAFolderHierarchyWeHaveDeleted) {
3012 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3013 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3013 CHECK(dir.good()); 3014 CHECK(dir.good());
3014 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); 3015 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10);
3015 mock_server_->AddUpdateDirectory(2, 1, "joe", 1, 10); 3016 mock_server_->AddUpdateDirectory(2, 1, "joe", 1, 10);
3016 LoopSyncShare(); 3017 LoopSyncShare();
3017 { 3018 {
3018 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 3019 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
3019 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 3020 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
3020 ASSERT_TRUE(bob.good()); 3021 ASSERT_TRUE(bob.good());
3021 bob.Put(IS_UNSYNCED, true); 3022 bob.Put(IS_UNSYNCED, true);
3022 bob.Put(IS_DEL, true); 3023 bob.Put(IS_DEL, true);
3023 MutableEntry joe(&trans, GET_BY_ID, ids_.FromNumber(2)); 3024 MutableEntry joe(&trans, GET_BY_ID, ids_.FromNumber(2));
3024 ASSERT_TRUE(joe.good()); 3025 ASSERT_TRUE(joe.good());
3025 joe.Put(IS_UNSYNCED, true); 3026 joe.Put(IS_UNSYNCED, true);
3026 joe.Put(IS_DEL, true); 3027 joe.Put(IS_DEL, true);
3027 } 3028 }
3028 mock_server_->AddUpdateDirectory(3, 2, "fred", 2, 20); 3029 mock_server_->AddUpdateDirectory(3, 2, "fred", 2, 20);
3029 mock_server_->set_conflict_all_commits(true); 3030 mock_server_->set_conflict_all_commits(true);
3030 LoopSyncShare(); 3031 LoopSyncShare();
3031 LoopSyncShare(); 3032 LoopSyncShare();
3032 { 3033 {
3033 ReadTransaction trans(dir, __FILE__, __LINE__); 3034 ReadTransaction trans(dir, FROM_HERE);
3034 Entry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 3035 Entry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
3035 ASSERT_TRUE(bob.good()); 3036 ASSERT_TRUE(bob.good());
3036 Entry joe(&trans, GET_BY_ID, ids_.FromNumber(2)); 3037 Entry joe(&trans, GET_BY_ID, ids_.FromNumber(2));
3037 ASSERT_TRUE(joe.good()); 3038 ASSERT_TRUE(joe.good());
3038 Entry fred(&trans, GET_BY_ID, ids_.FromNumber(3)); 3039 Entry fred(&trans, GET_BY_ID, ids_.FromNumber(3));
3039 ASSERT_TRUE(fred.good()); 3040 ASSERT_TRUE(fred.good());
3040 EXPECT_FALSE(fred.Get(IS_UNSYNCED)); 3041 EXPECT_FALSE(fred.Get(IS_UNSYNCED));
3041 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); 3042 EXPECT_TRUE(bob.Get(IS_UNSYNCED));
3042 EXPECT_TRUE(joe.Get(IS_UNSYNCED)); 3043 EXPECT_TRUE(joe.Get(IS_UNSYNCED));
3043 EXPECT_TRUE(fred.Get(PARENT_ID) == joe.Get(ID)); 3044 EXPECT_TRUE(fred.Get(PARENT_ID) == joe.Get(ID));
3044 EXPECT_TRUE(joe.Get(PARENT_ID) == bob.Get(ID)); 3045 EXPECT_TRUE(joe.Get(PARENT_ID) == bob.Get(ID));
3045 EXPECT_TRUE(bob.Get(PARENT_ID) == root_id_); 3046 EXPECT_TRUE(bob.Get(PARENT_ID) == root_id_);
3046 EXPECT_FALSE(fred.Get(IS_UNAPPLIED_UPDATE)); 3047 EXPECT_FALSE(fred.Get(IS_UNAPPLIED_UPDATE));
3047 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); 3048 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE));
3048 EXPECT_FALSE(joe.Get(IS_UNAPPLIED_UPDATE)); 3049 EXPECT_FALSE(joe.Get(IS_UNAPPLIED_UPDATE));
3049 } 3050 }
3050 saw_syncer_event_ = false; 3051 saw_syncer_event_ = false;
3051 } 3052 }
3052 3053
3053 TEST_F(SyncerTest, NewServerItemInAFolderHierarchyWeHaveDeleted2) { 3054 TEST_F(SyncerTest, NewServerItemInAFolderHierarchyWeHaveDeleted2) {
3054 // The difference here is that the hierarchy's not in the root. We have 3055 // The difference here is that the hierarchy's not in the root. We have
3055 // another entry that shouldn't be touched. 3056 // another entry that shouldn't be touched.
3056 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3057 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3057 CHECK(dir.good()); 3058 CHECK(dir.good());
3058 mock_server_->AddUpdateDirectory(4, 0, "susan", 1, 10); 3059 mock_server_->AddUpdateDirectory(4, 0, "susan", 1, 10);
3059 mock_server_->AddUpdateDirectory(1, 4, "bob", 1, 10); 3060 mock_server_->AddUpdateDirectory(1, 4, "bob", 1, 10);
3060 mock_server_->AddUpdateDirectory(2, 1, "joe", 1, 10); 3061 mock_server_->AddUpdateDirectory(2, 1, "joe", 1, 10);
3061 LoopSyncShare(); 3062 LoopSyncShare();
3062 { 3063 {
3063 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 3064 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
3064 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 3065 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
3065 ASSERT_TRUE(bob.good()); 3066 ASSERT_TRUE(bob.good());
3066 bob.Put(IS_UNSYNCED, true); 3067 bob.Put(IS_UNSYNCED, true);
3067 bob.Put(IS_DEL, true); 3068 bob.Put(IS_DEL, true);
3068 MutableEntry joe(&trans, GET_BY_ID, ids_.FromNumber(2)); 3069 MutableEntry joe(&trans, GET_BY_ID, ids_.FromNumber(2));
3069 ASSERT_TRUE(joe.good()); 3070 ASSERT_TRUE(joe.good());
3070 joe.Put(IS_UNSYNCED, true); 3071 joe.Put(IS_UNSYNCED, true);
3071 joe.Put(IS_DEL, true); 3072 joe.Put(IS_DEL, true);
3072 } 3073 }
3073 mock_server_->AddUpdateDirectory(3, 2, "fred", 2, 20); 3074 mock_server_->AddUpdateDirectory(3, 2, "fred", 2, 20);
3074 mock_server_->set_conflict_all_commits(true); 3075 mock_server_->set_conflict_all_commits(true);
3075 LoopSyncShare(); 3076 LoopSyncShare();
3076 LoopSyncShare(); 3077 LoopSyncShare();
3077 { 3078 {
3078 ReadTransaction trans(dir, __FILE__, __LINE__); 3079 ReadTransaction trans(dir, FROM_HERE);
3079 Entry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 3080 Entry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
3080 ASSERT_TRUE(bob.good()); 3081 ASSERT_TRUE(bob.good());
3081 Entry joe(&trans, GET_BY_ID, ids_.FromNumber(2)); 3082 Entry joe(&trans, GET_BY_ID, ids_.FromNumber(2));
3082 ASSERT_TRUE(joe.good()); 3083 ASSERT_TRUE(joe.good());
3083 Entry fred(&trans, GET_BY_ID, ids_.FromNumber(3)); 3084 Entry fred(&trans, GET_BY_ID, ids_.FromNumber(3));
3084 ASSERT_TRUE(fred.good()); 3085 ASSERT_TRUE(fred.good());
3085 Entry susan(&trans, GET_BY_ID, ids_.FromNumber(4)); 3086 Entry susan(&trans, GET_BY_ID, ids_.FromNumber(4));
3086 ASSERT_TRUE(susan.good()); 3087 ASSERT_TRUE(susan.good());
3087 EXPECT_FALSE(susan.Get(IS_UNSYNCED)); 3088 EXPECT_FALSE(susan.Get(IS_UNSYNCED));
3088 EXPECT_FALSE(fred.Get(IS_UNSYNCED)); 3089 EXPECT_FALSE(fred.Get(IS_UNSYNCED));
(...skipping 19 matching lines...) Expand all
3108 static const int64 susan_int_id_ = 4; 3109 static const int64 susan_int_id_ = 4;
3109 3110
3110 void DeleteSusanInRoot() { 3111 void DeleteSusanInRoot() {
3111 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3112 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3112 ASSERT_TRUE(dir.good()); 3113 ASSERT_TRUE(dir.good());
3113 3114
3114 const syncable::Id susan_id = TestIdFactory::FromNumber(susan_int_id_); 3115 const syncable::Id susan_id = TestIdFactory::FromNumber(susan_int_id_);
3115 ASSERT_GT(countdown_till_delete_, 0); 3116 ASSERT_GT(countdown_till_delete_, 0);
3116 if (0 != --countdown_till_delete_) 3117 if (0 != --countdown_till_delete_)
3117 return; 3118 return;
3118 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 3119 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
3119 MutableEntry susan(&trans, GET_BY_ID, susan_id); 3120 MutableEntry susan(&trans, GET_BY_ID, susan_id);
3120 Directory::ChildHandles children; 3121 Directory::ChildHandles children;
3121 dir->GetChildHandlesById(&trans, susan.Get(ID), &children); 3122 dir->GetChildHandlesById(&trans, susan.Get(ID), &children);
3122 ASSERT_TRUE(0 == children.size()); 3123 ASSERT_TRUE(0 == children.size());
3123 susan.Put(IS_DEL, true); 3124 susan.Put(IS_DEL, true);
3124 susan.Put(IS_UNSYNCED, true); 3125 susan.Put(IS_UNSYNCED, true);
3125 } 3126 }
3126 3127
3127 protected: 3128 protected:
3128 int countdown_till_delete_; 3129 int countdown_till_delete_;
(...skipping 10 matching lines...) Expand all
3139 const syncable::Id joe_id = TestIdFactory::FromNumber(2); 3140 const syncable::Id joe_id = TestIdFactory::FromNumber(2);
3140 const syncable::Id fred_id = TestIdFactory::FromNumber(3); 3141 const syncable::Id fred_id = TestIdFactory::FromNumber(3);
3141 const syncable::Id susan_id = TestIdFactory::FromNumber(susan_int_id_); 3142 const syncable::Id susan_id = TestIdFactory::FromNumber(susan_int_id_);
3142 3143
3143 mock_server_->AddUpdateDirectory(susan_id, TestIdFactory::root(), 3144 mock_server_->AddUpdateDirectory(susan_id, TestIdFactory::root(),
3144 "susan", 1, 10); 3145 "susan", 1, 10);
3145 mock_server_->AddUpdateDirectory(bob_id, susan_id, "bob", 1, 10); 3146 mock_server_->AddUpdateDirectory(bob_id, susan_id, "bob", 1, 10);
3146 mock_server_->AddUpdateDirectory(joe_id, bob_id, "joe", 1, 10); 3147 mock_server_->AddUpdateDirectory(joe_id, bob_id, "joe", 1, 10);
3147 LoopSyncShare(); 3148 LoopSyncShare();
3148 { 3149 {
3149 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 3150 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
3150 MutableEntry bob(&trans, GET_BY_ID, bob_id); 3151 MutableEntry bob(&trans, GET_BY_ID, bob_id);
3151 ASSERT_TRUE(bob.good()); 3152 ASSERT_TRUE(bob.good());
3152 bob.Put(IS_UNSYNCED, true); 3153 bob.Put(IS_UNSYNCED, true);
3153 bob.Put(IS_DEL, true); 3154 bob.Put(IS_DEL, true);
3154 3155
3155 MutableEntry joe(&trans, GET_BY_ID, joe_id); 3156 MutableEntry joe(&trans, GET_BY_ID, joe_id);
3156 ASSERT_TRUE(joe.good()); 3157 ASSERT_TRUE(joe.good());
3157 joe.Put(IS_UNSYNCED, true); 3158 joe.Put(IS_UNSYNCED, true);
3158 joe.Put(IS_DEL, true); 3159 joe.Put(IS_DEL, true);
3159 } 3160 }
3160 mock_server_->AddUpdateDirectory(fred_id, joe_id, "fred", 2, 20); 3161 mock_server_->AddUpdateDirectory(fred_id, joe_id, "fred", 2, 20);
3161 mock_server_->set_conflict_all_commits(true); 3162 mock_server_->set_conflict_all_commits(true);
3162 countdown_till_delete_ = 2; 3163 countdown_till_delete_ = 2;
3163 syncer_->pre_conflict_resolution_closure_ = 3164 syncer_->pre_conflict_resolution_closure_ =
3164 NewCallback<SusanDeletingTest>(this, 3165 NewCallback<SusanDeletingTest>(this,
3165 &SusanDeletingTest::DeleteSusanInRoot); 3166 &SusanDeletingTest::DeleteSusanInRoot);
3166 SyncShareAsDelegate(); 3167 SyncShareAsDelegate();
3167 SyncShareAsDelegate(); 3168 SyncShareAsDelegate();
3168 { 3169 {
3169 ReadTransaction trans(dir, __FILE__, __LINE__); 3170 ReadTransaction trans(dir, FROM_HERE);
3170 Entry bob(&trans, GET_BY_ID, bob_id); 3171 Entry bob(&trans, GET_BY_ID, bob_id);
3171 ASSERT_TRUE(bob.good()); 3172 ASSERT_TRUE(bob.good());
3172 Entry joe(&trans, GET_BY_ID, joe_id); 3173 Entry joe(&trans, GET_BY_ID, joe_id);
3173 ASSERT_TRUE(joe.good()); 3174 ASSERT_TRUE(joe.good());
3174 Entry fred(&trans, GET_BY_ID, fred_id); 3175 Entry fred(&trans, GET_BY_ID, fred_id);
3175 ASSERT_TRUE(fred.good()); 3176 ASSERT_TRUE(fred.good());
3176 Entry susan(&trans, GET_BY_ID, susan_id); 3177 Entry susan(&trans, GET_BY_ID, susan_id);
3177 ASSERT_TRUE(susan.good()); 3178 ASSERT_TRUE(susan.good());
3178 EXPECT_FALSE(susan.Get(IS_UNAPPLIED_UPDATE)); 3179 EXPECT_FALSE(susan.Get(IS_UNAPPLIED_UPDATE));
3179 EXPECT_TRUE(fred.Get(IS_UNAPPLIED_UPDATE)); 3180 EXPECT_TRUE(fred.Get(IS_UNAPPLIED_UPDATE));
3180 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); 3181 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE));
3181 EXPECT_FALSE(joe.Get(IS_UNAPPLIED_UPDATE)); 3182 EXPECT_FALSE(joe.Get(IS_UNAPPLIED_UPDATE));
3182 EXPECT_TRUE(susan.Get(IS_UNSYNCED)); 3183 EXPECT_TRUE(susan.Get(IS_UNSYNCED));
3183 EXPECT_FALSE(fred.Get(IS_UNSYNCED)); 3184 EXPECT_FALSE(fred.Get(IS_UNSYNCED));
3184 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); 3185 EXPECT_TRUE(bob.Get(IS_UNSYNCED));
3185 EXPECT_TRUE(joe.Get(IS_UNSYNCED)); 3186 EXPECT_TRUE(joe.Get(IS_UNSYNCED));
3186 } 3187 }
3187 EXPECT_TRUE(0 == countdown_till_delete_); 3188 EXPECT_TRUE(0 == countdown_till_delete_);
3188 delete syncer_->pre_conflict_resolution_closure_; 3189 delete syncer_->pre_conflict_resolution_closure_;
3189 syncer_->pre_conflict_resolution_closure_ = NULL; 3190 syncer_->pre_conflict_resolution_closure_ = NULL;
3190 LoopSyncShare(); 3191 LoopSyncShare();
3191 LoopSyncShare(); 3192 LoopSyncShare();
3192 { 3193 {
3193 ReadTransaction trans(dir, __FILE__, __LINE__); 3194 ReadTransaction trans(dir, FROM_HERE);
3194 Entry bob(&trans, GET_BY_ID, bob_id); 3195 Entry bob(&trans, GET_BY_ID, bob_id);
3195 ASSERT_TRUE(bob.good()); 3196 ASSERT_TRUE(bob.good());
3196 Entry joe(&trans, GET_BY_ID, joe_id); 3197 Entry joe(&trans, GET_BY_ID, joe_id);
3197 ASSERT_TRUE(joe.good()); 3198 ASSERT_TRUE(joe.good());
3198 Entry fred(&trans, GET_BY_ID, fred_id); 3199 Entry fred(&trans, GET_BY_ID, fred_id);
3199 ASSERT_TRUE(fred.good()); 3200 ASSERT_TRUE(fred.good());
3200 Entry susan(&trans, GET_BY_ID, susan_id); 3201 Entry susan(&trans, GET_BY_ID, susan_id);
3201 ASSERT_TRUE(susan.good()); 3202 ASSERT_TRUE(susan.good());
3202 EXPECT_TRUE(susan.Get(IS_UNSYNCED)); 3203 EXPECT_TRUE(susan.Get(IS_UNSYNCED));
3203 EXPECT_FALSE(fred.Get(IS_UNSYNCED)); 3204 EXPECT_FALSE(fred.Get(IS_UNSYNCED));
(...skipping 19 matching lines...) Expand all
3223 const syncable::Id fred_id = ids_.NewServerId(); 3224 const syncable::Id fred_id = ids_.NewServerId();
3224 const syncable::Id alice_id = ids_.NewServerId(); 3225 const syncable::Id alice_id = ids_.NewServerId();
3225 3226
3226 mock_server_->AddUpdateDirectory(bob_id, TestIdFactory::root(), 3227 mock_server_->AddUpdateDirectory(bob_id, TestIdFactory::root(),
3227 "bob", 1, 10); 3228 "bob", 1, 10);
3228 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(), 3229 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(),
3229 "fred", 1, 10); 3230 "fred", 1, 10);
3230 mock_server_->AddUpdateDirectory(alice_id, fred_id, "alice", 1, 10); 3231 mock_server_->AddUpdateDirectory(alice_id, fred_id, "alice", 1, 10);
3231 SyncShareAsDelegate(); 3232 SyncShareAsDelegate();
3232 { 3233 {
3233 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 3234 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
3234 MutableEntry bob(&trans, GET_BY_ID, bob_id); 3235 MutableEntry bob(&trans, GET_BY_ID, bob_id);
3235 ASSERT_TRUE(bob.good()); 3236 ASSERT_TRUE(bob.good());
3236 bob.Put(IS_UNSYNCED, true); 3237 bob.Put(IS_UNSYNCED, true);
3237 bob.Put(PARENT_ID, alice_id); // Move into alice. 3238 bob.Put(PARENT_ID, alice_id); // Move into alice.
3238 } 3239 }
3239 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(), 3240 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(),
3240 "fred", 2, 20); 3241 "fred", 2, 20);
3241 mock_server_->SetLastUpdateDeleted(); 3242 mock_server_->SetLastUpdateDeleted();
3242 mock_server_->AddUpdateDirectory(alice_id, TestIdFactory::root(), 3243 mock_server_->AddUpdateDirectory(alice_id, TestIdFactory::root(),
3243 "alice", 2, 20); 3244 "alice", 2, 20);
3244 mock_server_->SetLastUpdateDeleted(); 3245 mock_server_->SetLastUpdateDeleted();
3245 mock_server_->set_conflict_all_commits(true); 3246 mock_server_->set_conflict_all_commits(true);
3246 SyncShareAsDelegate(); 3247 SyncShareAsDelegate();
3247 SyncShareAsDelegate(); 3248 SyncShareAsDelegate();
3248 { 3249 {
3249 // Bob is the entry at the bottom of the tree. 3250 // Bob is the entry at the bottom of the tree.
3250 // The tree should be regenerated and old IDs removed. 3251 // The tree should be regenerated and old IDs removed.
3251 ReadTransaction trans(dir, __FILE__, __LINE__); 3252 ReadTransaction trans(dir, FROM_HERE);
3252 Entry bob(&trans, GET_BY_ID, bob_id); 3253 Entry bob(&trans, GET_BY_ID, bob_id);
3253 ASSERT_TRUE(bob.good()); 3254 ASSERT_TRUE(bob.good());
3254 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); 3255 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE));
3255 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); 3256 EXPECT_TRUE(bob.Get(IS_UNSYNCED));
3256 3257
3257 // Old one should be deleted, but new one should have been made. 3258 // Old one should be deleted, but new one should have been made.
3258 Entry dead_alice(&trans, GET_BY_ID, alice_id); 3259 Entry dead_alice(&trans, GET_BY_ID, alice_id);
3259 EXPECT_FALSE(dead_alice.good()); 3260 EXPECT_FALSE(dead_alice.good());
3260 EXPECT_NE(bob.Get(PARENT_ID), alice_id); 3261 EXPECT_NE(bob.Get(PARENT_ID), alice_id);
3261 3262
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3295 const syncable::Id susan_id = ids_.NewServerId(); 3296 const syncable::Id susan_id = ids_.NewServerId();
3296 3297
3297 mock_server_->AddUpdateDirectory(bob_id, TestIdFactory::root(), 3298 mock_server_->AddUpdateDirectory(bob_id, TestIdFactory::root(),
3298 "bob", 1, 10); 3299 "bob", 1, 10);
3299 mock_server_->AddUpdateDirectory(susan_id, TestIdFactory::root(), 3300 mock_server_->AddUpdateDirectory(susan_id, TestIdFactory::root(),
3300 "susan", 1, 10); 3301 "susan", 1, 10);
3301 mock_server_->AddUpdateDirectory(fred_id, susan_id, "fred", 1, 10); 3302 mock_server_->AddUpdateDirectory(fred_id, susan_id, "fred", 1, 10);
3302 mock_server_->AddUpdateDirectory(alice_id, fred_id, "alice", 1, 10); 3303 mock_server_->AddUpdateDirectory(alice_id, fred_id, "alice", 1, 10);
3303 SyncShareAsDelegate(); 3304 SyncShareAsDelegate();
3304 { 3305 {
3305 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 3306 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
3306 MutableEntry bob(&trans, GET_BY_ID, bob_id); 3307 MutableEntry bob(&trans, GET_BY_ID, bob_id);
3307 ASSERT_TRUE(bob.good()); 3308 ASSERT_TRUE(bob.good());
3308 bob.Put(IS_UNSYNCED, true); 3309 bob.Put(IS_UNSYNCED, true);
3309 bob.Put(PARENT_ID, alice_id); // Move into alice. 3310 bob.Put(PARENT_ID, alice_id); // Move into alice.
3310 } 3311 }
3311 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(), 3312 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(),
3312 "fred", 2, 20); 3313 "fred", 2, 20);
3313 mock_server_->SetLastUpdateDeleted(); 3314 mock_server_->SetLastUpdateDeleted();
3314 mock_server_->AddUpdateDirectory(alice_id, TestIdFactory::root(), 3315 mock_server_->AddUpdateDirectory(alice_id, TestIdFactory::root(),
3315 "alice", 2, 20); 3316 "alice", 2, 20);
3316 mock_server_->SetLastUpdateDeleted(); 3317 mock_server_->SetLastUpdateDeleted();
3317 mock_server_->set_conflict_all_commits(true); 3318 mock_server_->set_conflict_all_commits(true);
3318 SyncShareAsDelegate(); 3319 SyncShareAsDelegate();
3319 SyncShareAsDelegate(); 3320 SyncShareAsDelegate();
3320 { 3321 {
3321 // Root 3322 // Root
3322 // |- Susan 3323 // |- Susan
3323 // |- Fred 3324 // |- Fred
3324 // |- Alice 3325 // |- Alice
3325 // |- Bob 3326 // |- Bob
3326 3327
3327 ReadTransaction trans(dir, __FILE__, __LINE__); 3328 ReadTransaction trans(dir, FROM_HERE);
3328 Entry bob(&trans, GET_BY_ID, bob_id); 3329 Entry bob(&trans, GET_BY_ID, bob_id);
3329 ASSERT_TRUE(bob.good()); 3330 ASSERT_TRUE(bob.good());
3330 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); 3331 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE));
3331 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); // Parent changed 3332 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); // Parent changed
3332 EXPECT_NE(bob.Get(PARENT_ID), alice_id); 3333 EXPECT_NE(bob.Get(PARENT_ID), alice_id);
3333 3334
3334 // New one was born, this is the old one 3335 // New one was born, this is the old one
3335 Entry dead_alice(&trans, GET_BY_ID, alice_id); 3336 Entry dead_alice(&trans, GET_BY_ID, alice_id);
3336 EXPECT_FALSE(dead_alice.good()); 3337 EXPECT_FALSE(dead_alice.good());
3337 3338
(...skipping 24 matching lines...) Expand all
3362 } 3363 }
3363 saw_syncer_event_ = false; 3364 saw_syncer_event_ = false;
3364 } 3365 }
3365 3366
3366 // This test is to reproduce a check failure. Sometimes we would get a bad ID 3367 // This test is to reproduce a check failure. Sometimes we would get a bad ID
3367 // back when creating an entry. 3368 // back when creating an entry.
3368 TEST_F(SyncerTest, DuplicateIDReturn) { 3369 TEST_F(SyncerTest, DuplicateIDReturn) {
3369 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3370 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3370 ASSERT_TRUE(dir.good()); 3371 ASSERT_TRUE(dir.good());
3371 { 3372 {
3372 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 3373 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
3373 MutableEntry folder(&trans, CREATE, trans.root_id(), "bob"); 3374 MutableEntry folder(&trans, CREATE, trans.root_id(), "bob");
3374 ASSERT_TRUE(folder.good()); 3375 ASSERT_TRUE(folder.good());
3375 folder.Put(IS_UNSYNCED, true); 3376 folder.Put(IS_UNSYNCED, true);
3376 folder.Put(IS_DIR, true); 3377 folder.Put(IS_DIR, true);
3377 folder.Put(SPECIFICS, DefaultBookmarkSpecifics()); 3378 folder.Put(SPECIFICS, DefaultBookmarkSpecifics());
3378 MutableEntry folder2(&trans, CREATE, trans.root_id(), "fred"); 3379 MutableEntry folder2(&trans, CREATE, trans.root_id(), "fred");
3379 ASSERT_TRUE(folder2.good()); 3380 ASSERT_TRUE(folder2.good());
3380 folder2.Put(IS_UNSYNCED, false); 3381 folder2.Put(IS_UNSYNCED, false);
3381 folder2.Put(IS_DIR, true); 3382 folder2.Put(IS_DIR, true);
3382 folder2.Put(SPECIFICS, DefaultBookmarkSpecifics()); 3383 folder2.Put(SPECIFICS, DefaultBookmarkSpecifics());
3383 folder2.Put(BASE_VERSION, 3); 3384 folder2.Put(BASE_VERSION, 3);
3384 folder2.Put(ID, syncable::Id::CreateFromServerId("mock_server:10000")); 3385 folder2.Put(ID, syncable::Id::CreateFromServerId("mock_server:10000"));
3385 } 3386 }
3386 mock_server_->set_next_new_id(10000); 3387 mock_server_->set_next_new_id(10000);
3387 EXPECT_TRUE(1 == dir->unsynced_entity_count()); 3388 EXPECT_TRUE(1 == dir->unsynced_entity_count());
3388 // we get back a bad id in here (should never happen). 3389 // we get back a bad id in here (should never happen).
3389 SyncShareAsDelegate(); 3390 SyncShareAsDelegate();
3390 EXPECT_TRUE(1 == dir->unsynced_entity_count()); 3391 EXPECT_TRUE(1 == dir->unsynced_entity_count());
3391 SyncShareAsDelegate(); // another bad id in here. 3392 SyncShareAsDelegate(); // another bad id in here.
3392 EXPECT_TRUE(0 == dir->unsynced_entity_count()); 3393 EXPECT_TRUE(0 == dir->unsynced_entity_count());
3393 saw_syncer_event_ = false; 3394 saw_syncer_event_ = false;
3394 } 3395 }
3395 3396
3396 TEST_F(SyncerTest, DeletedEntryWithBadParentInLoopCalculation) { 3397 TEST_F(SyncerTest, DeletedEntryWithBadParentInLoopCalculation) {
3397 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3398 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3398 ASSERT_TRUE(dir.good()); 3399 ASSERT_TRUE(dir.good());
3399 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); 3400 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10);
3400 SyncShareAsDelegate(); 3401 SyncShareAsDelegate();
3401 { 3402 {
3402 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 3403 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
3403 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 3404 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
3404 ASSERT_TRUE(bob.good()); 3405 ASSERT_TRUE(bob.good());
3405 // This is valid, because the parent could have gone away a long time ago. 3406 // This is valid, because the parent could have gone away a long time ago.
3406 bob.Put(PARENT_ID, ids_.FromNumber(54)); 3407 bob.Put(PARENT_ID, ids_.FromNumber(54));
3407 bob.Put(IS_DEL, true); 3408 bob.Put(IS_DEL, true);
3408 bob.Put(IS_UNSYNCED, true); 3409 bob.Put(IS_UNSYNCED, true);
3409 } 3410 }
3410 mock_server_->AddUpdateDirectory(2, 1, "fred", 1, 10); 3411 mock_server_->AddUpdateDirectory(2, 1, "fred", 1, 10);
3411 SyncShareAsDelegate(); 3412 SyncShareAsDelegate();
3412 SyncShareAsDelegate(); 3413 SyncShareAsDelegate();
3413 } 3414 }
3414 3415
3415 TEST_F(SyncerTest, ConflictResolverMergeOverwritesLocalEntry) { 3416 TEST_F(SyncerTest, ConflictResolverMergeOverwritesLocalEntry) {
3416 // This test would die because it would rename a entry to a name that was 3417 // This test would die because it would rename a entry to a name that was
3417 // taken in the namespace 3418 // taken in the namespace
3418 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3419 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3419 CHECK(dir.good()); 3420 CHECK(dir.good());
3420 3421
3421 ConflictSet conflict_set; 3422 ConflictSet conflict_set;
3422 { 3423 {
3423 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 3424 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
3424 3425
3425 MutableEntry local_deleted(&trans, CREATE, trans.root_id(), "name"); 3426 MutableEntry local_deleted(&trans, CREATE, trans.root_id(), "name");
3426 local_deleted.Put(ID, ids_.FromNumber(1)); 3427 local_deleted.Put(ID, ids_.FromNumber(1));
3427 local_deleted.Put(BASE_VERSION, 1); 3428 local_deleted.Put(BASE_VERSION, 1);
3428 local_deleted.Put(IS_DEL, true); 3429 local_deleted.Put(IS_DEL, true);
3429 local_deleted.Put(IS_UNSYNCED, true); 3430 local_deleted.Put(IS_UNSYNCED, true);
3430 3431
3431 MutableEntry in_the_way(&trans, CREATE, trans.root_id(), "name"); 3432 MutableEntry in_the_way(&trans, CREATE, trans.root_id(), "name");
3432 in_the_way.Put(ID, ids_.FromNumber(2)); 3433 in_the_way.Put(ID, ids_.FromNumber(2));
3433 in_the_way.Put(BASE_VERSION, 1); 3434 in_the_way.Put(BASE_VERSION, 1);
3434 3435
3435 MutableEntry update(&trans, CREATE_NEW_UPDATE_ITEM, ids_.FromNumber(3)); 3436 MutableEntry update(&trans, CREATE_NEW_UPDATE_ITEM, ids_.FromNumber(3));
3436 update.Put(BASE_VERSION, 1); 3437 update.Put(BASE_VERSION, 1);
3437 update.Put(SERVER_NON_UNIQUE_NAME, "name"); 3438 update.Put(SERVER_NON_UNIQUE_NAME, "name");
3438 update.Put(PARENT_ID, ids_.FromNumber(0)); 3439 update.Put(PARENT_ID, ids_.FromNumber(0));
3439 update.Put(IS_UNAPPLIED_UPDATE, true); 3440 update.Put(IS_UNAPPLIED_UPDATE, true);
3440 3441
3441 conflict_set.push_back(ids_.FromNumber(1)); 3442 conflict_set.push_back(ids_.FromNumber(1));
3442 conflict_set.push_back(ids_.FromNumber(3)); 3443 conflict_set.push_back(ids_.FromNumber(3));
3443 } 3444 }
3444 { 3445 {
3445 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 3446 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
3446 context_->resolver()->ProcessConflictSet(&trans, &conflict_set, 50); 3447 context_->resolver()->ProcessConflictSet(&trans, &conflict_set, 50);
3447 } 3448 }
3448 } 3449 }
3449 3450
3450 TEST_F(SyncerTest, ConflictResolverMergesLocalDeleteAndServerUpdate) { 3451 TEST_F(SyncerTest, ConflictResolverMergesLocalDeleteAndServerUpdate) {
3451 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3452 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3452 CHECK(dir.good()); 3453 CHECK(dir.good());
3453 3454
3454 { 3455 {
3455 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 3456 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
3456 3457
3457 MutableEntry local_deleted(&trans, CREATE, trans.root_id(), "name"); 3458 MutableEntry local_deleted(&trans, CREATE, trans.root_id(), "name");
3458 local_deleted.Put(ID, ids_.FromNumber(1)); 3459 local_deleted.Put(ID, ids_.FromNumber(1));
3459 local_deleted.Put(BASE_VERSION, 1); 3460 local_deleted.Put(BASE_VERSION, 1);
3460 local_deleted.Put(IS_DEL, true); 3461 local_deleted.Put(IS_DEL, true);
3461 local_deleted.Put(IS_DIR, false); 3462 local_deleted.Put(IS_DIR, false);
3462 local_deleted.Put(IS_UNSYNCED, true); 3463 local_deleted.Put(IS_UNSYNCED, true);
3463 local_deleted.Put(SPECIFICS, DefaultBookmarkSpecifics()); 3464 local_deleted.Put(SPECIFICS, DefaultBookmarkSpecifics());
3464 } 3465 }
3465 3466
3466 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10); 3467 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10);
3467 3468
3468 // We don't care about actually committing, just the resolution. 3469 // We don't care about actually committing, just the resolution.
3469 mock_server_->set_conflict_all_commits(true); 3470 mock_server_->set_conflict_all_commits(true);
3470 SyncShareAsDelegate(); 3471 SyncShareAsDelegate();
3471 3472
3472 { 3473 {
3473 ReadTransaction trans(dir, __FILE__, __LINE__); 3474 ReadTransaction trans(dir, FROM_HERE);
3474 Entry local_deleted(&trans, GET_BY_ID, ids_.FromNumber(1)); 3475 Entry local_deleted(&trans, GET_BY_ID, ids_.FromNumber(1));
3475 EXPECT_TRUE(local_deleted.Get(BASE_VERSION) == 10); 3476 EXPECT_TRUE(local_deleted.Get(BASE_VERSION) == 10);
3476 EXPECT_TRUE(local_deleted.Get(IS_UNAPPLIED_UPDATE) == false); 3477 EXPECT_TRUE(local_deleted.Get(IS_UNAPPLIED_UPDATE) == false);
3477 EXPECT_TRUE(local_deleted.Get(IS_UNSYNCED) == true); 3478 EXPECT_TRUE(local_deleted.Get(IS_UNSYNCED) == true);
3478 EXPECT_TRUE(local_deleted.Get(IS_DEL) == true); 3479 EXPECT_TRUE(local_deleted.Get(IS_DEL) == true);
3479 EXPECT_TRUE(local_deleted.Get(IS_DIR) == false); 3480 EXPECT_TRUE(local_deleted.Get(IS_DIR) == false);
3480 } 3481 }
3481 } 3482 }
3482 3483
3483 // See what happens if the IS_DIR bit gets flipped. This can cause us 3484 // See what happens if the IS_DIR bit gets flipped. This can cause us
3484 // all kinds of disasters. 3485 // all kinds of disasters.
3485 TEST_F(SyncerTest, UpdateFlipsTheFolderBit) { 3486 TEST_F(SyncerTest, UpdateFlipsTheFolderBit) {
3486 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3487 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3487 CHECK(dir.good()); 3488 CHECK(dir.good());
3488 3489
3489 // Local object: a deleted directory (container), revision 1, unsynced. 3490 // Local object: a deleted directory (container), revision 1, unsynced.
3490 { 3491 {
3491 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 3492 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
3492 3493
3493 MutableEntry local_deleted(&trans, CREATE, trans.root_id(), "name"); 3494 MutableEntry local_deleted(&trans, CREATE, trans.root_id(), "name");
3494 local_deleted.Put(ID, ids_.FromNumber(1)); 3495 local_deleted.Put(ID, ids_.FromNumber(1));
3495 local_deleted.Put(BASE_VERSION, 1); 3496 local_deleted.Put(BASE_VERSION, 1);
3496 local_deleted.Put(IS_DEL, true); 3497 local_deleted.Put(IS_DEL, true);
3497 local_deleted.Put(IS_DIR, true); 3498 local_deleted.Put(IS_DIR, true);
3498 local_deleted.Put(IS_UNSYNCED, true); 3499 local_deleted.Put(IS_UNSYNCED, true);
3499 local_deleted.Put(SPECIFICS, DefaultBookmarkSpecifics()); 3500 local_deleted.Put(SPECIFICS, DefaultBookmarkSpecifics());
3500 } 3501 }
3501 3502
3502 // Server update: entry-type object (not a container), revision 10. 3503 // Server update: entry-type object (not a container), revision 10.
3503 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10); 3504 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10);
3504 3505
3505 // Don't attempt to commit. 3506 // Don't attempt to commit.
3506 mock_server_->set_conflict_all_commits(true); 3507 mock_server_->set_conflict_all_commits(true);
3507 3508
3508 // The syncer should not attempt to apply the invalid update. 3509 // The syncer should not attempt to apply the invalid update.
3509 SyncShareAsDelegate(); 3510 SyncShareAsDelegate();
3510 3511
3511 { 3512 {
3512 ReadTransaction trans(dir, __FILE__, __LINE__); 3513 ReadTransaction trans(dir, FROM_HERE);
3513 Entry local_deleted(&trans, GET_BY_ID, ids_.FromNumber(1)); 3514 Entry local_deleted(&trans, GET_BY_ID, ids_.FromNumber(1));
3514 EXPECT_TRUE(local_deleted.Get(BASE_VERSION) == 1); 3515 EXPECT_TRUE(local_deleted.Get(BASE_VERSION) == 1);
3515 EXPECT_TRUE(local_deleted.Get(IS_UNAPPLIED_UPDATE) == false); 3516 EXPECT_TRUE(local_deleted.Get(IS_UNAPPLIED_UPDATE) == false);
3516 EXPECT_TRUE(local_deleted.Get(IS_UNSYNCED) == true); 3517 EXPECT_TRUE(local_deleted.Get(IS_UNSYNCED) == true);
3517 EXPECT_TRUE(local_deleted.Get(IS_DEL) == true); 3518 EXPECT_TRUE(local_deleted.Get(IS_DEL) == true);
3518 EXPECT_TRUE(local_deleted.Get(IS_DIR) == true); 3519 EXPECT_TRUE(local_deleted.Get(IS_DIR) == true);
3519 } 3520 }
3520 } 3521 }
3521 3522
3522 TEST(SyncerSyncProcessState, MergeSetsTest) { 3523 TEST(SyncerSyncProcessState, MergeSetsTest) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3555 // Bug Synopsis: 3556 // Bug Synopsis:
3556 // Merge conflict resolution will merge a new local entry with another entry 3557 // Merge conflict resolution will merge a new local entry with another entry
3557 // that needs updates, resulting in CHECK. 3558 // that needs updates, resulting in CHECK.
3558 TEST_F(SyncerTest, MergingExistingItems) { 3559 TEST_F(SyncerTest, MergingExistingItems) {
3559 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3560 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3560 CHECK(dir.good()); 3561 CHECK(dir.good());
3561 mock_server_->set_conflict_all_commits(true); 3562 mock_server_->set_conflict_all_commits(true);
3562 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10); 3563 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10);
3563 SyncShareAsDelegate(); 3564 SyncShareAsDelegate();
3564 { 3565 {
3565 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 3566 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
3566 MutableEntry entry(&trans, CREATE, trans.root_id(), "Copy of base"); 3567 MutableEntry entry(&trans, CREATE, trans.root_id(), "Copy of base");
3567 WriteTestDataToEntry(&trans, &entry); 3568 WriteTestDataToEntry(&trans, &entry);
3568 } 3569 }
3569 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50); 3570 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50);
3570 SyncRepeatedlyToTriggerConflictResolution(session_.get()); 3571 SyncRepeatedlyToTriggerConflictResolution(session_.get());
3571 } 3572 }
3572 3573
3573 TEST_F(SyncerTest, OneBajillionUpdates) { 3574 TEST_F(SyncerTest, OneBajillionUpdates) {
3574 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3575 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3575 CHECK(dir.good()); 3576 CHECK(dir.good());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3611 mock_server_->NextUpdateBatch(); 3612 mock_server_->NextUpdateBatch();
3612 mock_server_->SetNewTimestamp(i + 1); 3613 mock_server_->SetNewTimestamp(i + 1);
3613 mock_server_->SetChangesRemaining(depth - i); 3614 mock_server_->SetChangesRemaining(depth - i);
3614 } 3615 }
3615 3616
3616 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 3617 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
3617 EXPECT_FALSE(session_->status_controller()->syncer_status().syncer_stuck); 3618 EXPECT_FALSE(session_->status_controller()->syncer_status().syncer_stuck);
3618 3619
3619 // Ensure our folder hasn't somehow applied. 3620 // Ensure our folder hasn't somehow applied.
3620 { 3621 {
3621 ReadTransaction trans(dir, __FILE__, __LINE__); 3622 ReadTransaction trans(dir, FROM_HERE);
3622 Entry child(&trans, GET_BY_ID, stuck_entry_id); 3623 Entry child(&trans, GET_BY_ID, stuck_entry_id);
3623 EXPECT_TRUE(child.good()); 3624 EXPECT_TRUE(child.good());
3624 EXPECT_TRUE(child.Get(IS_UNAPPLIED_UPDATE)); 3625 EXPECT_TRUE(child.Get(IS_UNAPPLIED_UPDATE));
3625 EXPECT_TRUE(child.Get(IS_DEL)); 3626 EXPECT_TRUE(child.Get(IS_DEL));
3626 EXPECT_FALSE(child.Get(IS_UNSYNCED)); 3627 EXPECT_FALSE(child.Get(IS_UNSYNCED));
3627 } 3628 }
3628 3629
3629 // And finally the folder. 3630 // And finally the folder.
3630 mock_server_->AddUpdateDirectory(folder_id, 3631 mock_server_->AddUpdateDirectory(folder_id,
3631 TestIdFactory::root(), "folder", 1, 1); 3632 TestIdFactory::root(), "folder", 1, 1);
3632 mock_server_->SetChangesRemaining(0); 3633 mock_server_->SetChangesRemaining(0);
3633 LoopSyncShare(); 3634 LoopSyncShare();
3634 LoopSyncShare(); 3635 LoopSyncShare();
3635 // Check that everything is as expected after the commit. 3636 // Check that everything is as expected after the commit.
3636 { 3637 {
3637 ReadTransaction trans(dir, __FILE__, __LINE__); 3638 ReadTransaction trans(dir, FROM_HERE);
3638 Entry entry(&trans, GET_BY_ID, folder_id); 3639 Entry entry(&trans, GET_BY_ID, folder_id);
3639 ASSERT_TRUE(entry.good()); 3640 ASSERT_TRUE(entry.good());
3640 Entry child(&trans, GET_BY_ID, stuck_entry_id); 3641 Entry child(&trans, GET_BY_ID, stuck_entry_id);
3641 EXPECT_EQ(entry.Get(ID), child.Get(PARENT_ID)); 3642 EXPECT_EQ(entry.Get(ID), child.Get(PARENT_ID));
3642 EXPECT_EQ("stuck", child.Get(NON_UNIQUE_NAME)); 3643 EXPECT_EQ("stuck", child.Get(NON_UNIQUE_NAME));
3643 EXPECT_TRUE(child.good()); 3644 EXPECT_TRUE(child.good());
3644 } 3645 }
3645 } 3646 }
3646 3647
3647 TEST_F(SyncerTest, DontMergeTwoExistingItems) { 3648 TEST_F(SyncerTest, DontMergeTwoExistingItems) {
3648 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3649 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3649 EXPECT_TRUE(dir.good()); 3650 EXPECT_TRUE(dir.good());
3650 mock_server_->set_conflict_all_commits(true); 3651 mock_server_->set_conflict_all_commits(true);
3651 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10); 3652 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10);
3652 mock_server_->AddUpdateBookmark(2, 0, "base2", 10, 10); 3653 mock_server_->AddUpdateBookmark(2, 0, "base2", 10, 10);
3653 SyncShareAsDelegate(); 3654 SyncShareAsDelegate();
3654 { 3655 {
3655 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 3656 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
3656 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); 3657 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2));
3657 ASSERT_TRUE(entry.good()); 3658 ASSERT_TRUE(entry.good());
3658 EXPECT_TRUE(entry.Put(NON_UNIQUE_NAME, "Copy of base")); 3659 EXPECT_TRUE(entry.Put(NON_UNIQUE_NAME, "Copy of base"));
3659 entry.Put(IS_UNSYNCED, true); 3660 entry.Put(IS_UNSYNCED, true);
3660 } 3661 }
3661 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50); 3662 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50);
3662 SyncRepeatedlyToTriggerConflictResolution(session_.get()); 3663 SyncRepeatedlyToTriggerConflictResolution(session_.get());
3663 { 3664 {
3664 ReadTransaction trans(dir, __FILE__, __LINE__); 3665 ReadTransaction trans(dir, FROM_HERE);
3665 Entry entry1(&trans, GET_BY_ID, ids_.FromNumber(1)); 3666 Entry entry1(&trans, GET_BY_ID, ids_.FromNumber(1));
3666 EXPECT_FALSE(entry1.Get(IS_UNAPPLIED_UPDATE)); 3667 EXPECT_FALSE(entry1.Get(IS_UNAPPLIED_UPDATE));
3667 EXPECT_FALSE(entry1.Get(IS_UNSYNCED)); 3668 EXPECT_FALSE(entry1.Get(IS_UNSYNCED));
3668 EXPECT_FALSE(entry1.Get(IS_DEL)); 3669 EXPECT_FALSE(entry1.Get(IS_DEL));
3669 Entry entry2(&trans, GET_BY_ID, ids_.FromNumber(2)); 3670 Entry entry2(&trans, GET_BY_ID, ids_.FromNumber(2));
3670 EXPECT_FALSE(entry2.Get(IS_UNAPPLIED_UPDATE)); 3671 EXPECT_FALSE(entry2.Get(IS_UNAPPLIED_UPDATE));
3671 EXPECT_TRUE(entry2.Get(IS_UNSYNCED)); 3672 EXPECT_TRUE(entry2.Get(IS_UNSYNCED));
3672 EXPECT_FALSE(entry2.Get(IS_DEL)); 3673 EXPECT_FALSE(entry2.Get(IS_DEL));
3673 EXPECT_EQ(entry1.Get(NON_UNIQUE_NAME), entry2.Get(NON_UNIQUE_NAME)); 3674 EXPECT_EQ(entry1.Get(NON_UNIQUE_NAME), entry2.Get(NON_UNIQUE_NAME));
3674 } 3675 }
3675 } 3676 }
3676 3677
3677 TEST_F(SyncerTest, TestUndeleteUpdate) { 3678 TEST_F(SyncerTest, TestUndeleteUpdate) {
3678 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3679 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3679 EXPECT_TRUE(dir.good()); 3680 EXPECT_TRUE(dir.good());
3680 mock_server_->set_conflict_all_commits(true); 3681 mock_server_->set_conflict_all_commits(true);
3681 mock_server_->AddUpdateDirectory(1, 0, "foo", 1, 1); 3682 mock_server_->AddUpdateDirectory(1, 0, "foo", 1, 1);
3682 mock_server_->AddUpdateDirectory(2, 1, "bar", 1, 2); 3683 mock_server_->AddUpdateDirectory(2, 1, "bar", 1, 2);
3683 SyncShareAsDelegate(); 3684 SyncShareAsDelegate();
3684 mock_server_->AddUpdateDirectory(2, 1, "bar", 2, 3); 3685 mock_server_->AddUpdateDirectory(2, 1, "bar", 2, 3);
3685 mock_server_->SetLastUpdateDeleted(); 3686 mock_server_->SetLastUpdateDeleted();
3686 SyncShareAsDelegate(); 3687 SyncShareAsDelegate();
3687 3688
3688 int64 metahandle; 3689 int64 metahandle;
3689 { 3690 {
3690 ReadTransaction trans(dir, __FILE__, __LINE__); 3691 ReadTransaction trans(dir, FROM_HERE);
3691 Entry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); 3692 Entry entry(&trans, GET_BY_ID, ids_.FromNumber(2));
3692 ASSERT_TRUE(entry.good()); 3693 ASSERT_TRUE(entry.good());
3693 EXPECT_TRUE(entry.Get(IS_DEL)); 3694 EXPECT_TRUE(entry.Get(IS_DEL));
3694 metahandle = entry.Get(META_HANDLE); 3695 metahandle = entry.Get(META_HANDLE);
3695 } 3696 }
3696 mock_server_->AddUpdateDirectory(1, 0, "foo", 2, 4); 3697 mock_server_->AddUpdateDirectory(1, 0, "foo", 2, 4);
3697 mock_server_->SetLastUpdateDeleted(); 3698 mock_server_->SetLastUpdateDeleted();
3698 SyncShareAsDelegate(); 3699 SyncShareAsDelegate();
3699 // This used to be rejected as it's an undeletion. Now, it results in moving 3700 // This used to be rejected as it's an undeletion. Now, it results in moving
3700 // the delete path aside. 3701 // the delete path aside.
3701 mock_server_->AddUpdateDirectory(2, 1, "bar", 3, 5); 3702 mock_server_->AddUpdateDirectory(2, 1, "bar", 3, 5);
3702 SyncShareAsDelegate(); 3703 SyncShareAsDelegate();
3703 { 3704 {
3704 ReadTransaction trans(dir, __FILE__, __LINE__); 3705 ReadTransaction trans(dir, FROM_HERE);
3705 Entry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); 3706 Entry entry(&trans, GET_BY_ID, ids_.FromNumber(2));
3706 ASSERT_TRUE(entry.good()); 3707 ASSERT_TRUE(entry.good());
3707 EXPECT_TRUE(entry.Get(IS_DEL)); 3708 EXPECT_TRUE(entry.Get(IS_DEL));
3708 EXPECT_FALSE(entry.Get(SERVER_IS_DEL)); 3709 EXPECT_FALSE(entry.Get(SERVER_IS_DEL));
3709 EXPECT_TRUE(entry.Get(IS_UNAPPLIED_UPDATE)); 3710 EXPECT_TRUE(entry.Get(IS_UNAPPLIED_UPDATE));
3710 EXPECT_NE(entry.Get(META_HANDLE), metahandle); 3711 EXPECT_NE(entry.Get(META_HANDLE), metahandle);
3711 } 3712 }
3712 } 3713 }
3713 3714
3714 TEST_F(SyncerTest, TestMoveSanitizedNamedFolder) { 3715 TEST_F(SyncerTest, TestMoveSanitizedNamedFolder) {
3715 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3716 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3716 EXPECT_TRUE(dir.good()); 3717 EXPECT_TRUE(dir.good());
3717 mock_server_->AddUpdateDirectory(1, 0, "foo", 1, 1); 3718 mock_server_->AddUpdateDirectory(1, 0, "foo", 1, 1);
3718 mock_server_->AddUpdateDirectory(2, 0, ":::", 1, 2); 3719 mock_server_->AddUpdateDirectory(2, 0, ":::", 1, 2);
3719 SyncShareAsDelegate(); 3720 SyncShareAsDelegate();
3720 { 3721 {
3721 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 3722 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
3722 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); 3723 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2));
3723 ASSERT_TRUE(entry.good()); 3724 ASSERT_TRUE(entry.good());
3724 EXPECT_TRUE(entry.Put(PARENT_ID, ids_.FromNumber(1))); 3725 EXPECT_TRUE(entry.Put(PARENT_ID, ids_.FromNumber(1)));
3725 EXPECT_TRUE(entry.Put(IS_UNSYNCED, true)); 3726 EXPECT_TRUE(entry.Put(IS_UNSYNCED, true));
3726 } 3727 }
3727 SyncShareAsDelegate(); 3728 SyncShareAsDelegate();
3728 // We use the same sync ts as before so our times match up. 3729 // We use the same sync ts as before so our times match up.
3729 mock_server_->AddUpdateDirectory(2, 1, ":::", 2, 2); 3730 mock_server_->AddUpdateDirectory(2, 1, ":::", 2, 2);
3730 SyncShareAsDelegate(); 3731 SyncShareAsDelegate();
3731 } 3732 }
3732 3733
3733 // Don't crash when this occurs. 3734 // Don't crash when this occurs.
3734 TEST_F(SyncerTest, UpdateWhereParentIsNotAFolder) { 3735 TEST_F(SyncerTest, UpdateWhereParentIsNotAFolder) {
3735 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3736 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3736 CHECK(dir.good()); 3737 CHECK(dir.good());
3737 mock_server_->AddUpdateBookmark(1, 0, "B", 10, 10); 3738 mock_server_->AddUpdateBookmark(1, 0, "B", 10, 10);
3738 mock_server_->AddUpdateDirectory(2, 1, "BookmarkParent", 10, 10); 3739 mock_server_->AddUpdateDirectory(2, 1, "BookmarkParent", 10, 10);
3739 // Used to cause a CHECK 3740 // Used to cause a CHECK
3740 SyncShareAsDelegate(); 3741 SyncShareAsDelegate();
3741 { 3742 {
3742 ReadTransaction rtrans(dir, __FILE__, __LINE__); 3743 ReadTransaction rtrans(dir, FROM_HERE);
3743 Entry good_entry(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); 3744 Entry good_entry(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1));
3744 ASSERT_TRUE(good_entry.good()); 3745 ASSERT_TRUE(good_entry.good());
3745 EXPECT_FALSE(good_entry.Get(IS_UNAPPLIED_UPDATE)); 3746 EXPECT_FALSE(good_entry.Get(IS_UNAPPLIED_UPDATE));
3746 Entry bad_parent(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(2)); 3747 Entry bad_parent(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(2));
3747 ASSERT_TRUE(bad_parent.good()); 3748 ASSERT_TRUE(bad_parent.good());
3748 EXPECT_TRUE(bad_parent.Get(IS_UNAPPLIED_UPDATE)); 3749 EXPECT_TRUE(bad_parent.Get(IS_UNAPPLIED_UPDATE));
3749 } 3750 }
3750 } 3751 }
3751 3752
3752 const char kRootId[] = "0"; 3753 const char kRootId[] = "0";
3753 3754
3754 TEST_F(SyncerTest, DirectoryUpdateTest) { 3755 TEST_F(SyncerTest, DirectoryUpdateTest) {
3755 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3756 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3756 CHECK(dir.good()); 3757 CHECK(dir.good());
3757 3758
3758 Id in_root_id = ids_.NewServerId(); 3759 Id in_root_id = ids_.NewServerId();
3759 Id in_in_root_id = ids_.NewServerId(); 3760 Id in_in_root_id = ids_.NewServerId();
3760 3761
3761 mock_server_->AddUpdateDirectory(in_root_id, TestIdFactory::root(), 3762 mock_server_->AddUpdateDirectory(in_root_id, TestIdFactory::root(),
3762 "in_root_name", 2, 2); 3763 "in_root_name", 2, 2);
3763 mock_server_->AddUpdateDirectory(in_in_root_id, in_root_id, 3764 mock_server_->AddUpdateDirectory(in_in_root_id, in_root_id,
3764 "in_in_root_name", 3, 3); 3765 "in_in_root_name", 3, 3);
3765 SyncShareAsDelegate(); 3766 SyncShareAsDelegate();
3766 { 3767 {
3767 ReadTransaction trans(dir, __FILE__, __LINE__); 3768 ReadTransaction trans(dir, FROM_HERE);
3768 Entry in_root(&trans, GET_BY_ID, in_root_id); 3769 Entry in_root(&trans, GET_BY_ID, in_root_id);
3769 ASSERT_TRUE(in_root.good()); 3770 ASSERT_TRUE(in_root.good());
3770 EXPECT_EQ("in_root_name", in_root.Get(NON_UNIQUE_NAME)); 3771 EXPECT_EQ("in_root_name", in_root.Get(NON_UNIQUE_NAME));
3771 EXPECT_EQ(TestIdFactory::root(), in_root.Get(PARENT_ID)); 3772 EXPECT_EQ(TestIdFactory::root(), in_root.Get(PARENT_ID));
3772 3773
3773 Entry in_in_root(&trans, GET_BY_ID, in_in_root_id); 3774 Entry in_in_root(&trans, GET_BY_ID, in_in_root_id);
3774 ASSERT_TRUE(in_in_root.good()); 3775 ASSERT_TRUE(in_in_root.good());
3775 EXPECT_EQ("in_in_root_name", in_in_root.Get(NON_UNIQUE_NAME)); 3776 EXPECT_EQ("in_in_root_name", in_in_root.Get(NON_UNIQUE_NAME));
3776 EXPECT_EQ(in_root_id, in_in_root.Get(PARENT_ID)); 3777 EXPECT_EQ(in_root_id, in_in_root.Get(PARENT_ID));
3777 } 3778 }
3778 } 3779 }
3779 3780
3780 TEST_F(SyncerTest, DirectoryCommitTest) { 3781 TEST_F(SyncerTest, DirectoryCommitTest) {
3781 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3782 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3782 CHECK(dir.good()); 3783 CHECK(dir.good());
3783 3784
3784 syncable::Id in_root_id, in_dir_id; 3785 syncable::Id in_root_id, in_dir_id;
3785 int64 foo_metahandle; 3786 int64 foo_metahandle;
3786 int64 bar_metahandle; 3787 int64 bar_metahandle;
3787 3788
3788 { 3789 {
3789 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 3790 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
3790 MutableEntry parent(&wtrans, syncable::CREATE, root_id_, "foo"); 3791 MutableEntry parent(&wtrans, syncable::CREATE, root_id_, "foo");
3791 ASSERT_TRUE(parent.good()); 3792 ASSERT_TRUE(parent.good());
3792 parent.Put(syncable::IS_UNSYNCED, true); 3793 parent.Put(syncable::IS_UNSYNCED, true);
3793 parent.Put(syncable::IS_DIR, true); 3794 parent.Put(syncable::IS_DIR, true);
3794 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 3795 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
3795 in_root_id = parent.Get(syncable::ID); 3796 in_root_id = parent.Get(syncable::ID);
3796 foo_metahandle = parent.Get(META_HANDLE); 3797 foo_metahandle = parent.Get(META_HANDLE);
3797 3798
3798 MutableEntry child(&wtrans, syncable::CREATE, parent.Get(ID), "bar"); 3799 MutableEntry child(&wtrans, syncable::CREATE, parent.Get(ID), "bar");
3799 ASSERT_TRUE(child.good()); 3800 ASSERT_TRUE(child.good());
3800 child.Put(syncable::IS_UNSYNCED, true); 3801 child.Put(syncable::IS_UNSYNCED, true);
3801 child.Put(syncable::IS_DIR, true); 3802 child.Put(syncable::IS_DIR, true);
3802 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 3803 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
3803 bar_metahandle = child.Get(META_HANDLE); 3804 bar_metahandle = child.Get(META_HANDLE);
3804 in_dir_id = parent.Get(syncable::ID); 3805 in_dir_id = parent.Get(syncable::ID);
3805 } 3806 }
3806 SyncShareAsDelegate(); 3807 SyncShareAsDelegate();
3807 { 3808 {
3808 ReadTransaction trans(dir, __FILE__, __LINE__); 3809 ReadTransaction trans(dir, FROM_HERE);
3809 Entry fail_by_old_id_entry(&trans, GET_BY_ID, in_root_id); 3810 Entry fail_by_old_id_entry(&trans, GET_BY_ID, in_root_id);
3810 ASSERT_FALSE(fail_by_old_id_entry.good()); 3811 ASSERT_FALSE(fail_by_old_id_entry.good());
3811 3812
3812 Entry foo_entry(&trans, GET_BY_HANDLE, foo_metahandle); 3813 Entry foo_entry(&trans, GET_BY_HANDLE, foo_metahandle);
3813 ASSERT_TRUE(foo_entry.good()); 3814 ASSERT_TRUE(foo_entry.good());
3814 EXPECT_EQ("foo", foo_entry.Get(NON_UNIQUE_NAME)); 3815 EXPECT_EQ("foo", foo_entry.Get(NON_UNIQUE_NAME));
3815 EXPECT_NE(foo_entry.Get(syncable::ID), in_root_id); 3816 EXPECT_NE(foo_entry.Get(syncable::ID), in_root_id);
3816 3817
3817 Entry bar_entry(&trans, GET_BY_HANDLE, bar_metahandle); 3818 Entry bar_entry(&trans, GET_BY_HANDLE, bar_metahandle);
3818 ASSERT_TRUE(bar_entry.good()); 3819 ASSERT_TRUE(bar_entry.good());
3819 EXPECT_EQ("bar", bar_entry.Get(NON_UNIQUE_NAME)); 3820 EXPECT_EQ("bar", bar_entry.Get(NON_UNIQUE_NAME));
3820 EXPECT_NE(bar_entry.Get(syncable::ID), in_dir_id); 3821 EXPECT_NE(bar_entry.Get(syncable::ID), in_dir_id);
3821 EXPECT_EQ(foo_entry.Get(syncable::ID), bar_entry.Get(PARENT_ID)); 3822 EXPECT_EQ(foo_entry.Get(syncable::ID), bar_entry.Get(PARENT_ID));
3822 } 3823 }
3823 } 3824 }
3824 3825
3825 TEST_F(SyncerTest, ConflictSetSizeReducedToOne) { 3826 TEST_F(SyncerTest, ConflictSetSizeReducedToOne) {
3826 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3827 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3827 CHECK(dir.good()); 3828 CHECK(dir.good());
3828 3829
3829 syncable::Id in_root_id = ids_.NewServerId(); 3830 syncable::Id in_root_id = ids_.NewServerId();
3830 3831
3831 mock_server_->AddUpdateBookmark(in_root_id, TestIdFactory::root(), 3832 mock_server_->AddUpdateBookmark(in_root_id, TestIdFactory::root(),
3832 "in_root", 1, 1); 3833 "in_root", 1, 1);
3833 SyncShareAsDelegate(); 3834 SyncShareAsDelegate();
3834 { 3835 {
3835 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 3836 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
3836 MutableEntry oentry(&trans, GET_BY_ID, in_root_id); 3837 MutableEntry oentry(&trans, GET_BY_ID, in_root_id);
3837 ASSERT_TRUE(oentry.good()); 3838 ASSERT_TRUE(oentry.good());
3838 oentry.Put(NON_UNIQUE_NAME, "old_in_root"); 3839 oentry.Put(NON_UNIQUE_NAME, "old_in_root");
3839 WriteTestDataToEntry(&trans, &oentry); 3840 WriteTestDataToEntry(&trans, &oentry);
3840 MutableEntry entry(&trans, CREATE, trans.root_id(), "in_root"); 3841 MutableEntry entry(&trans, CREATE, trans.root_id(), "in_root");
3841 ASSERT_TRUE(entry.good()); 3842 ASSERT_TRUE(entry.good());
3842 WriteTestDataToEntry(&trans, &entry); 3843 WriteTestDataToEntry(&trans, &entry);
3843 } 3844 }
3844 mock_server_->set_conflict_all_commits(true); 3845 mock_server_->set_conflict_all_commits(true);
3845 // This SyncShare call used to result in a CHECK failure. 3846 // This SyncShare call used to result in a CHECK failure.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3882 syncable::Id folder_one_id = ids_.FromNumber(1); 3883 syncable::Id folder_one_id = ids_.FromNumber(1);
3883 syncable::Id folder_two_id = ids_.FromNumber(2); 3884 syncable::Id folder_two_id = ids_.FromNumber(2);
3884 3885
3885 mock_server_->AddUpdateDirectory(folder_one_id, TestIdFactory::root(), 3886 mock_server_->AddUpdateDirectory(folder_one_id, TestIdFactory::root(),
3886 "folder_one", 1, 1); 3887 "folder_one", 1, 1);
3887 mock_server_->AddUpdateDirectory(folder_two_id, TestIdFactory::root(), 3888 mock_server_->AddUpdateDirectory(folder_two_id, TestIdFactory::root(),
3888 "folder_two", 1, 1); 3889 "folder_two", 1, 1);
3889 SyncShareAsDelegate(); 3890 SyncShareAsDelegate();
3890 { 3891 {
3891 // A moved entry should send an "old parent." 3892 // A moved entry should send an "old parent."
3892 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 3893 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
3893 MutableEntry entry(&trans, GET_BY_ID, folder_one_id); 3894 MutableEntry entry(&trans, GET_BY_ID, folder_one_id);
3894 ASSERT_TRUE(entry.good()); 3895 ASSERT_TRUE(entry.good());
3895 entry.Put(PARENT_ID, folder_two_id); 3896 entry.Put(PARENT_ID, folder_two_id);
3896 entry.Put(IS_UNSYNCED, true); 3897 entry.Put(IS_UNSYNCED, true);
3897 // A new entry should send no "old parent." 3898 // A new entry should send no "old parent."
3898 MutableEntry create(&trans, CREATE, trans.root_id(), "new_folder"); 3899 MutableEntry create(&trans, CREATE, trans.root_id(), "new_folder");
3899 create.Put(IS_UNSYNCED, true); 3900 create.Put(IS_UNSYNCED, true);
3900 create.Put(SPECIFICS, DefaultBookmarkSpecifics()); 3901 create.Put(SPECIFICS, DefaultBookmarkSpecifics());
3901 } 3902 }
3902 SyncShareAsDelegate(); 3903 SyncShareAsDelegate();
3903 const sync_pb::CommitMessage& commit = mock_server_->last_sent_commit(); 3904 const sync_pb::CommitMessage& commit = mock_server_->last_sent_commit();
3904 ASSERT_TRUE(2 == commit.entries_size()); 3905 ASSERT_TRUE(2 == commit.entries_size());
3905 EXPECT_TRUE(commit.entries(0).parent_id_string() == "2"); 3906 EXPECT_TRUE(commit.entries(0).parent_id_string() == "2");
3906 EXPECT_TRUE(commit.entries(0).old_parent_id() == "0"); 3907 EXPECT_TRUE(commit.entries(0).old_parent_id() == "0");
3907 EXPECT_FALSE(commit.entries(1).has_old_parent_id()); 3908 EXPECT_FALSE(commit.entries(1).has_old_parent_id());
3908 } 3909 }
3909 3910
3910 TEST_F(SyncerTest, Test64BitVersionSupport) { 3911 TEST_F(SyncerTest, Test64BitVersionSupport) {
3911 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3912 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3912 CHECK(dir.good()); 3913 CHECK(dir.good());
3913 int64 really_big_int = std::numeric_limits<int64>::max() - 12; 3914 int64 really_big_int = std::numeric_limits<int64>::max() - 12;
3914 const string name("ringo's dang orang ran rings around my o-ring"); 3915 const string name("ringo's dang orang ran rings around my o-ring");
3915 int64 item_metahandle; 3916 int64 item_metahandle;
3916 3917
3917 // Try writing max int64 to the version fields of a meta entry. 3918 // Try writing max int64 to the version fields of a meta entry.
3918 { 3919 {
3919 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 3920 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
3920 MutableEntry entry(&wtrans, syncable::CREATE, wtrans.root_id(), name); 3921 MutableEntry entry(&wtrans, syncable::CREATE, wtrans.root_id(), name);
3921 ASSERT_TRUE(entry.good()); 3922 ASSERT_TRUE(entry.good());
3922 entry.Put(syncable::BASE_VERSION, really_big_int); 3923 entry.Put(syncable::BASE_VERSION, really_big_int);
3923 entry.Put(syncable::SERVER_VERSION, really_big_int); 3924 entry.Put(syncable::SERVER_VERSION, really_big_int);
3924 entry.Put(syncable::ID, ids_.NewServerId()); 3925 entry.Put(syncable::ID, ids_.NewServerId());
3925 item_metahandle = entry.Get(META_HANDLE); 3926 item_metahandle = entry.Get(META_HANDLE);
3926 } 3927 }
3927 // Now read it back out and make sure the value is max int64. 3928 // Now read it back out and make sure the value is max int64.
3928 ReadTransaction rtrans(dir, __FILE__, __LINE__); 3929 ReadTransaction rtrans(dir, FROM_HERE);
3929 Entry entry(&rtrans, syncable::GET_BY_HANDLE, item_metahandle); 3930 Entry entry(&rtrans, syncable::GET_BY_HANDLE, item_metahandle);
3930 ASSERT_TRUE(entry.good()); 3931 ASSERT_TRUE(entry.good());
3931 EXPECT_TRUE(really_big_int == entry.Get(syncable::BASE_VERSION)); 3932 EXPECT_TRUE(really_big_int == entry.Get(syncable::BASE_VERSION));
3932 } 3933 }
3933 3934
3934 TEST_F(SyncerTest, TestSimpleUndelete) { 3935 TEST_F(SyncerTest, TestSimpleUndelete) {
3935 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root(); 3936 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root();
3936 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3937 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3937 EXPECT_TRUE(dir.good()); 3938 EXPECT_TRUE(dir.good());
3938 mock_server_->set_conflict_all_commits(true); 3939 mock_server_->set_conflict_all_commits(true);
3939 // Let there be an entry from the server. 3940 // Let there be an entry from the server.
3940 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10); 3941 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10);
3941 SyncShareAsDelegate(); 3942 SyncShareAsDelegate();
3942 // Check it out and delete it. 3943 // Check it out and delete it.
3943 { 3944 {
3944 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 3945 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
3945 MutableEntry entry(&wtrans, GET_BY_ID, id); 3946 MutableEntry entry(&wtrans, GET_BY_ID, id);
3946 ASSERT_TRUE(entry.good()); 3947 ASSERT_TRUE(entry.good());
3947 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE)); 3948 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE));
3948 EXPECT_FALSE(entry.Get(IS_UNSYNCED)); 3949 EXPECT_FALSE(entry.Get(IS_UNSYNCED));
3949 EXPECT_FALSE(entry.Get(IS_DEL)); 3950 EXPECT_FALSE(entry.Get(IS_DEL));
3950 // Delete it locally. 3951 // Delete it locally.
3951 entry.Put(IS_DEL, true); 3952 entry.Put(IS_DEL, true);
3952 } 3953 }
3953 SyncShareAsDelegate(); 3954 SyncShareAsDelegate();
3954 // Confirm we see IS_DEL and not SERVER_IS_DEL. 3955 // Confirm we see IS_DEL and not SERVER_IS_DEL.
3955 { 3956 {
3956 ReadTransaction trans(dir, __FILE__, __LINE__); 3957 ReadTransaction trans(dir, FROM_HERE);
3957 Entry entry(&trans, GET_BY_ID, id); 3958 Entry entry(&trans, GET_BY_ID, id);
3958 ASSERT_TRUE(entry.good()); 3959 ASSERT_TRUE(entry.good());
3959 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE)); 3960 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE));
3960 EXPECT_FALSE(entry.Get(IS_UNSYNCED)); 3961 EXPECT_FALSE(entry.Get(IS_UNSYNCED));
3961 EXPECT_TRUE(entry.Get(IS_DEL)); 3962 EXPECT_TRUE(entry.Get(IS_DEL));
3962 EXPECT_FALSE(entry.Get(SERVER_IS_DEL)); 3963 EXPECT_FALSE(entry.Get(SERVER_IS_DEL));
3963 } 3964 }
3964 SyncShareAsDelegate(); 3965 SyncShareAsDelegate();
3965 // Update from server confirming deletion. 3966 // Update from server confirming deletion.
3966 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 11); 3967 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 11);
3967 mock_server_->SetLastUpdateDeleted(); 3968 mock_server_->SetLastUpdateDeleted();
3968 SyncShareAsDelegate(); 3969 SyncShareAsDelegate();
3969 // IS_DEL AND SERVER_IS_DEL now both true. 3970 // IS_DEL AND SERVER_IS_DEL now both true.
3970 { 3971 {
3971 ReadTransaction trans(dir, __FILE__, __LINE__); 3972 ReadTransaction trans(dir, FROM_HERE);
3972 Entry entry(&trans, GET_BY_ID, id); 3973 Entry entry(&trans, GET_BY_ID, id);
3973 ASSERT_TRUE(entry.good()); 3974 ASSERT_TRUE(entry.good());
3974 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE)); 3975 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE));
3975 EXPECT_FALSE(entry.Get(IS_UNSYNCED)); 3976 EXPECT_FALSE(entry.Get(IS_UNSYNCED));
3976 EXPECT_TRUE(entry.Get(IS_DEL)); 3977 EXPECT_TRUE(entry.Get(IS_DEL));
3977 EXPECT_TRUE(entry.Get(SERVER_IS_DEL)); 3978 EXPECT_TRUE(entry.Get(SERVER_IS_DEL));
3978 } 3979 }
3979 // Undelete from server. 3980 // Undelete from server.
3980 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 12); 3981 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 12);
3981 SyncShareAsDelegate(); 3982 SyncShareAsDelegate();
3982 // IS_DEL and SERVER_IS_DEL now both false. 3983 // IS_DEL and SERVER_IS_DEL now both false.
3983 { 3984 {
3984 ReadTransaction trans(dir, __FILE__, __LINE__); 3985 ReadTransaction trans(dir, FROM_HERE);
3985 Entry entry(&trans, GET_BY_ID, id); 3986 Entry entry(&trans, GET_BY_ID, id);
3986 ASSERT_TRUE(entry.good()); 3987 ASSERT_TRUE(entry.good());
3987 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE)); 3988 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE));
3988 EXPECT_FALSE(entry.Get(IS_UNSYNCED)); 3989 EXPECT_FALSE(entry.Get(IS_UNSYNCED));
3989 EXPECT_FALSE(entry.Get(IS_DEL)); 3990 EXPECT_FALSE(entry.Get(IS_DEL));
3990 EXPECT_FALSE(entry.Get(SERVER_IS_DEL)); 3991 EXPECT_FALSE(entry.Get(SERVER_IS_DEL));
3991 } 3992 }
3992 } 3993 }
3993 3994
3994 TEST_F(SyncerTest, TestUndeleteWithMissingDeleteUpdate) { 3995 TEST_F(SyncerTest, TestUndeleteWithMissingDeleteUpdate) {
3995 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root(); 3996 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root();
3996 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 3997 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
3997 EXPECT_TRUE(dir.good()); 3998 EXPECT_TRUE(dir.good());
3998 // Let there be a entry, from the server. 3999 // Let there be a entry, from the server.
3999 mock_server_->set_conflict_all_commits(true); 4000 mock_server_->set_conflict_all_commits(true);
4000 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10); 4001 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10);
4001 SyncShareAsDelegate(); 4002 SyncShareAsDelegate();
4002 // Check it out and delete it. 4003 // Check it out and delete it.
4003 { 4004 {
4004 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); 4005 WriteTransaction wtrans(dir, UNITTEST, FROM_HERE);
4005 MutableEntry entry(&wtrans, GET_BY_ID, id); 4006 MutableEntry entry(&wtrans, GET_BY_ID, id);
4006 ASSERT_TRUE(entry.good()); 4007 ASSERT_TRUE(entry.good());
4007 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE)); 4008 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE));
4008 EXPECT_FALSE(entry.Get(IS_UNSYNCED)); 4009 EXPECT_FALSE(entry.Get(IS_UNSYNCED));
4009 EXPECT_FALSE(entry.Get(IS_DEL)); 4010 EXPECT_FALSE(entry.Get(IS_DEL));
4010 // Delete it locally. 4011 // Delete it locally.
4011 entry.Put(IS_DEL, true); 4012 entry.Put(IS_DEL, true);
4012 } 4013 }
4013 SyncShareAsDelegate(); 4014 SyncShareAsDelegate();
4014 // Confirm we see IS_DEL and not SERVER_IS_DEL. 4015 // Confirm we see IS_DEL and not SERVER_IS_DEL.
4015 { 4016 {
4016 ReadTransaction trans(dir, __FILE__, __LINE__); 4017 ReadTransaction trans(dir, FROM_HERE);
4017 Entry entry(&trans, GET_BY_ID, id); 4018 Entry entry(&trans, GET_BY_ID, id);
4018 ASSERT_TRUE(entry.good()); 4019 ASSERT_TRUE(entry.good());
4019 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE)); 4020 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE));
4020 EXPECT_FALSE(entry.Get(IS_UNSYNCED)); 4021 EXPECT_FALSE(entry.Get(IS_UNSYNCED));
4021 EXPECT_TRUE(entry.Get(IS_DEL)); 4022 EXPECT_TRUE(entry.Get(IS_DEL));
4022 EXPECT_FALSE(entry.Get(SERVER_IS_DEL)); 4023 EXPECT_FALSE(entry.Get(SERVER_IS_DEL));
4023 } 4024 }
4024 SyncShareAsDelegate(); 4025 SyncShareAsDelegate();
4025 // Say we do not get an update from server confirming deletion. Undelete 4026 // Say we do not get an update from server confirming deletion. Undelete
4026 // from server 4027 // from server
4027 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 12); 4028 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 12);
4028 SyncShareAsDelegate(); 4029 SyncShareAsDelegate();
4029 // IS_DEL and SERVER_IS_DEL now both false. 4030 // IS_DEL and SERVER_IS_DEL now both false.
4030 { 4031 {
4031 ReadTransaction trans(dir, __FILE__, __LINE__); 4032 ReadTransaction trans(dir, FROM_HERE);
4032 Entry entry(&trans, GET_BY_ID, id); 4033 Entry entry(&trans, GET_BY_ID, id);
4033 ASSERT_TRUE(entry.good()); 4034 ASSERT_TRUE(entry.good());
4034 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE)); 4035 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE));
4035 EXPECT_FALSE(entry.Get(IS_UNSYNCED)); 4036 EXPECT_FALSE(entry.Get(IS_UNSYNCED));
4036 EXPECT_FALSE(entry.Get(IS_DEL)); 4037 EXPECT_FALSE(entry.Get(IS_DEL));
4037 EXPECT_FALSE(entry.Get(SERVER_IS_DEL)); 4038 EXPECT_FALSE(entry.Get(SERVER_IS_DEL));
4038 } 4039 }
4039 } 4040 }
4040 4041
4041 TEST_F(SyncerTest, TestUndeleteIgnoreCorrectlyUnappliedUpdate) { 4042 TEST_F(SyncerTest, TestUndeleteIgnoreCorrectlyUnappliedUpdate) {
(...skipping 13 matching lines...) Expand all
4055 TEST_F(SyncerTest, ClientTagServerCreatedUpdatesWork) { 4056 TEST_F(SyncerTest, ClientTagServerCreatedUpdatesWork) {
4056 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 4057 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
4057 EXPECT_TRUE(dir.good()); 4058 EXPECT_TRUE(dir.good());
4058 4059
4059 mock_server_->AddUpdateDirectory(1, 0, "permitem1", 1, 10); 4060 mock_server_->AddUpdateDirectory(1, 0, "permitem1", 1, 10);
4060 mock_server_->SetLastUpdateClientTag("permfolder"); 4061 mock_server_->SetLastUpdateClientTag("permfolder");
4061 4062
4062 SyncShareAsDelegate(); 4063 SyncShareAsDelegate();
4063 4064
4064 { 4065 {
4065 ReadTransaction trans(dir, __FILE__, __LINE__); 4066 ReadTransaction trans(dir, FROM_HERE);
4066 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder"); 4067 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder");
4067 ASSERT_TRUE(perm_folder.good()); 4068 ASSERT_TRUE(perm_folder.good());
4068 EXPECT_FALSE(perm_folder.Get(IS_DEL)); 4069 EXPECT_FALSE(perm_folder.Get(IS_DEL));
4069 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); 4070 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE));
4070 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED)); 4071 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED));
4071 EXPECT_EQ(perm_folder.Get(UNIQUE_CLIENT_TAG), "permfolder"); 4072 EXPECT_EQ(perm_folder.Get(UNIQUE_CLIENT_TAG), "permfolder");
4072 EXPECT_EQ(perm_folder.Get(NON_UNIQUE_NAME), "permitem1"); 4073 EXPECT_EQ(perm_folder.Get(NON_UNIQUE_NAME), "permitem1");
4073 } 4074 }
4074 4075
4075 mock_server_->AddUpdateDirectory(1, 0, "permitem_renamed", 10, 100); 4076 mock_server_->AddUpdateDirectory(1, 0, "permitem_renamed", 10, 100);
4076 mock_server_->SetLastUpdateClientTag("permfolder"); 4077 mock_server_->SetLastUpdateClientTag("permfolder");
4077 SyncShareAsDelegate(); 4078 SyncShareAsDelegate();
4078 4079
4079 { 4080 {
4080 ReadTransaction trans(dir, __FILE__, __LINE__); 4081 ReadTransaction trans(dir, FROM_HERE);
4081 4082
4082 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder"); 4083 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder");
4083 ASSERT_TRUE(perm_folder.good()); 4084 ASSERT_TRUE(perm_folder.good());
4084 EXPECT_FALSE(perm_folder.Get(IS_DEL)); 4085 EXPECT_FALSE(perm_folder.Get(IS_DEL));
4085 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); 4086 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE));
4086 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED)); 4087 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED));
4087 EXPECT_EQ(perm_folder.Get(UNIQUE_CLIENT_TAG), "permfolder"); 4088 EXPECT_EQ(perm_folder.Get(UNIQUE_CLIENT_TAG), "permfolder");
4088 EXPECT_EQ(perm_folder.Get(NON_UNIQUE_NAME), "permitem_renamed"); 4089 EXPECT_EQ(perm_folder.Get(NON_UNIQUE_NAME), "permitem_renamed");
4089 } 4090 }
4090 } 4091 }
4091 4092
4092 TEST_F(SyncerTest, ClientTagIllegalUpdateIgnored) { 4093 TEST_F(SyncerTest, ClientTagIllegalUpdateIgnored) {
4093 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 4094 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
4094 EXPECT_TRUE(dir.good()); 4095 EXPECT_TRUE(dir.good());
4095 4096
4096 mock_server_->AddUpdateDirectory(1, 0, "permitem1", 1, 10); 4097 mock_server_->AddUpdateDirectory(1, 0, "permitem1", 1, 10);
4097 mock_server_->SetLastUpdateClientTag("permfolder"); 4098 mock_server_->SetLastUpdateClientTag("permfolder");
4098 4099
4099 SyncShareAsDelegate(); 4100 SyncShareAsDelegate();
4100 4101
4101 { 4102 {
4102 ReadTransaction trans(dir, __FILE__, __LINE__); 4103 ReadTransaction trans(dir, FROM_HERE);
4103 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder"); 4104 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder");
4104 ASSERT_TRUE(perm_folder.good()); 4105 ASSERT_TRUE(perm_folder.good());
4105 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); 4106 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE));
4106 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED)); 4107 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED));
4107 EXPECT_EQ(perm_folder.Get(UNIQUE_CLIENT_TAG), "permfolder"); 4108 EXPECT_EQ(perm_folder.Get(UNIQUE_CLIENT_TAG), "permfolder");
4108 EXPECT_TRUE(perm_folder.Get(NON_UNIQUE_NAME) == "permitem1"); 4109 EXPECT_TRUE(perm_folder.Get(NON_UNIQUE_NAME) == "permitem1");
4109 EXPECT_TRUE(perm_folder.Get(ID).ServerKnows()); 4110 EXPECT_TRUE(perm_folder.Get(ID).ServerKnows());
4110 } 4111 }
4111 4112
4112 mock_server_->AddUpdateDirectory(1, 0, "permitem_renamed", 10, 100); 4113 mock_server_->AddUpdateDirectory(1, 0, "permitem_renamed", 10, 100);
4113 mock_server_->SetLastUpdateClientTag("wrongtag"); 4114 mock_server_->SetLastUpdateClientTag("wrongtag");
4114 SyncShareAsDelegate(); 4115 SyncShareAsDelegate();
4115 4116
4116 { 4117 {
4117 ReadTransaction trans(dir, __FILE__, __LINE__); 4118 ReadTransaction trans(dir, FROM_HERE);
4118 4119
4119 // This update is rejected because it has the same ID, but a 4120 // This update is rejected because it has the same ID, but a
4120 // different tag than one that is already on the client. 4121 // different tag than one that is already on the client.
4121 // The client has a ServerKnows ID, which cannot be overwritten. 4122 // The client has a ServerKnows ID, which cannot be overwritten.
4122 Entry rejected_update(&trans, GET_BY_CLIENT_TAG, "wrongtag"); 4123 Entry rejected_update(&trans, GET_BY_CLIENT_TAG, "wrongtag");
4123 EXPECT_FALSE(rejected_update.good()); 4124 EXPECT_FALSE(rejected_update.good());
4124 4125
4125 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder"); 4126 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder");
4126 ASSERT_TRUE(perm_folder.good()); 4127 ASSERT_TRUE(perm_folder.good());
4127 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); 4128 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE));
4128 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED)); 4129 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED));
4129 EXPECT_EQ(perm_folder.Get(NON_UNIQUE_NAME), "permitem1"); 4130 EXPECT_EQ(perm_folder.Get(NON_UNIQUE_NAME), "permitem1");
4130 } 4131 }
4131 } 4132 }
4132 4133
4133 TEST_F(SyncerTest, ClientTagUncommittedTagMatchesUpdate) { 4134 TEST_F(SyncerTest, ClientTagUncommittedTagMatchesUpdate) {
4134 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 4135 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
4135 EXPECT_TRUE(dir.good()); 4136 EXPECT_TRUE(dir.good());
4136 int64 original_metahandle = 0; 4137 int64 original_metahandle = 0;
4137 4138
4138 sync_pb::EntitySpecifics local_bookmark(DefaultBookmarkSpecifics()); 4139 sync_pb::EntitySpecifics local_bookmark(DefaultBookmarkSpecifics());
4139 local_bookmark.MutableExtension(sync_pb::bookmark)-> 4140 local_bookmark.MutableExtension(sync_pb::bookmark)->
4140 set_url("http://foo/localsite"); 4141 set_url("http://foo/localsite");
4141 sync_pb::EntitySpecifics server_bookmark(DefaultBookmarkSpecifics()); 4142 sync_pb::EntitySpecifics server_bookmark(DefaultBookmarkSpecifics());
4142 server_bookmark.MutableExtension(sync_pb::bookmark)-> 4143 server_bookmark.MutableExtension(sync_pb::bookmark)->
4143 set_url("http://bar/serversite"); 4144 set_url("http://bar/serversite");
4144 4145
4145 { 4146 {
4146 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 4147 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
4147 MutableEntry perm_folder(&trans, CREATE, ids_.root(), "clientname"); 4148 MutableEntry perm_folder(&trans, CREATE, ids_.root(), "clientname");
4148 ASSERT_TRUE(perm_folder.good()); 4149 ASSERT_TRUE(perm_folder.good());
4149 perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm"); 4150 perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm");
4150 perm_folder.Put(SPECIFICS, local_bookmark); 4151 perm_folder.Put(SPECIFICS, local_bookmark);
4151 perm_folder.Put(IS_UNSYNCED, true); 4152 perm_folder.Put(IS_UNSYNCED, true);
4152 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); 4153 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE));
4153 EXPECT_FALSE(perm_folder.Get(ID).ServerKnows()); 4154 EXPECT_FALSE(perm_folder.Get(ID).ServerKnows());
4154 original_metahandle = perm_folder.Get(META_HANDLE); 4155 original_metahandle = perm_folder.Get(META_HANDLE);
4155 } 4156 }
4156 4157
4157 mock_server_->AddUpdateBookmark(1, 0, "permitem_renamed", 10, 100); 4158 mock_server_->AddUpdateBookmark(1, 0, "permitem_renamed", 10, 100);
4158 mock_server_->SetLastUpdateClientTag("clientperm"); 4159 mock_server_->SetLastUpdateClientTag("clientperm");
4159 mock_server_->GetMutableLastUpdate()->mutable_specifics()-> 4160 mock_server_->GetMutableLastUpdate()->mutable_specifics()->
4160 CopyFrom(server_bookmark); 4161 CopyFrom(server_bookmark);
4161 mock_server_->set_conflict_all_commits(true); 4162 mock_server_->set_conflict_all_commits(true);
4162 4163
4163 SyncShareAsDelegate(); 4164 SyncShareAsDelegate();
4164 // This should cause client tag reunion, preserving the metahandle. 4165 // This should cause client tag reunion, preserving the metahandle.
4165 { 4166 {
4166 ReadTransaction trans(dir, __FILE__, __LINE__); 4167 ReadTransaction trans(dir, FROM_HERE);
4167 4168
4168 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "clientperm"); 4169 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "clientperm");
4169 ASSERT_TRUE(perm_folder.good()); 4170 ASSERT_TRUE(perm_folder.good());
4170 EXPECT_FALSE(perm_folder.Get(IS_DEL)); 4171 EXPECT_FALSE(perm_folder.Get(IS_DEL));
4171 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); 4172 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE));
4172 EXPECT_TRUE(perm_folder.Get(IS_UNSYNCED)); 4173 EXPECT_TRUE(perm_folder.Get(IS_UNSYNCED));
4173 EXPECT_EQ(10, perm_folder.Get(BASE_VERSION)); 4174 EXPECT_EQ(10, perm_folder.Get(BASE_VERSION));
4174 // Entry should have been given the new ID while preserving the 4175 // Entry should have been given the new ID while preserving the
4175 // metahandle; client should have won the conflict resolution. 4176 // metahandle; client should have won the conflict resolution.
4176 EXPECT_EQ(original_metahandle, perm_folder.Get(META_HANDLE)); 4177 EXPECT_EQ(original_metahandle, perm_folder.Get(META_HANDLE));
4177 EXPECT_EQ("clientperm", perm_folder.Get(UNIQUE_CLIENT_TAG)); 4178 EXPECT_EQ("clientperm", perm_folder.Get(UNIQUE_CLIENT_TAG));
4178 EXPECT_EQ("clientname", perm_folder.Get(NON_UNIQUE_NAME)); 4179 EXPECT_EQ("clientname", perm_folder.Get(NON_UNIQUE_NAME));
4179 EXPECT_EQ(local_bookmark.SerializeAsString(), 4180 EXPECT_EQ(local_bookmark.SerializeAsString(),
4180 perm_folder.Get(SPECIFICS).SerializeAsString()); 4181 perm_folder.Get(SPECIFICS).SerializeAsString());
4181 EXPECT_TRUE(perm_folder.Get(ID).ServerKnows()); 4182 EXPECT_TRUE(perm_folder.Get(ID).ServerKnows());
4182 } 4183 }
4183 4184
4184 mock_server_->set_conflict_all_commits(false); 4185 mock_server_->set_conflict_all_commits(false);
4185 SyncShareAsDelegate(); 4186 SyncShareAsDelegate();
4186 4187
4187 // The resolved entry ought to commit cleanly. 4188 // The resolved entry ought to commit cleanly.
4188 { 4189 {
4189 ReadTransaction trans(dir, __FILE__, __LINE__); 4190 ReadTransaction trans(dir, FROM_HERE);
4190 4191
4191 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "clientperm"); 4192 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "clientperm");
4192 ASSERT_TRUE(perm_folder.good()); 4193 ASSERT_TRUE(perm_folder.good());
4193 EXPECT_FALSE(perm_folder.Get(IS_DEL)); 4194 EXPECT_FALSE(perm_folder.Get(IS_DEL));
4194 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); 4195 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE));
4195 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED)); 4196 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED));
4196 EXPECT_TRUE(10 < perm_folder.Get(BASE_VERSION)); 4197 EXPECT_TRUE(10 < perm_folder.Get(BASE_VERSION));
4197 // Entry should have been given the new ID while preserving the 4198 // Entry should have been given the new ID while preserving the
4198 // metahandle; client should have won the conflict resolution. 4199 // metahandle; client should have won the conflict resolution.
4199 EXPECT_EQ(original_metahandle, perm_folder.Get(META_HANDLE)); 4200 EXPECT_EQ(original_metahandle, perm_folder.Get(META_HANDLE));
4200 EXPECT_EQ("clientperm", perm_folder.Get(UNIQUE_CLIENT_TAG)); 4201 EXPECT_EQ("clientperm", perm_folder.Get(UNIQUE_CLIENT_TAG));
4201 EXPECT_EQ("clientname", perm_folder.Get(NON_UNIQUE_NAME)); 4202 EXPECT_EQ("clientname", perm_folder.Get(NON_UNIQUE_NAME));
4202 EXPECT_EQ(local_bookmark.SerializeAsString(), 4203 EXPECT_EQ(local_bookmark.SerializeAsString(),
4203 perm_folder.Get(SPECIFICS).SerializeAsString()); 4204 perm_folder.Get(SPECIFICS).SerializeAsString());
4204 EXPECT_TRUE(perm_folder.Get(ID).ServerKnows()); 4205 EXPECT_TRUE(perm_folder.Get(ID).ServerKnows());
4205 } 4206 }
4206 } 4207 }
4207 4208
4208 TEST_F(SyncerTest, ClientTagConflictWithDeletedLocalEntry) { 4209 TEST_F(SyncerTest, ClientTagConflictWithDeletedLocalEntry) {
4209 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 4210 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
4210 EXPECT_TRUE(dir.good()); 4211 EXPECT_TRUE(dir.good());
4211 4212
4212 { 4213 {
4213 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 4214 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
4214 MutableEntry perm_folder(&trans, CREATE, ids_.root(), "clientname"); 4215 MutableEntry perm_folder(&trans, CREATE, ids_.root(), "clientname");
4215 ASSERT_TRUE(perm_folder.good()); 4216 ASSERT_TRUE(perm_folder.good());
4216 ASSERT_FALSE(perm_folder.Get(ID).ServerKnows()); 4217 ASSERT_FALSE(perm_folder.Get(ID).ServerKnows());
4217 perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm"); 4218 perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm");
4218 perm_folder.Put(SPECIFICS, DefaultBookmarkSpecifics()); 4219 perm_folder.Put(SPECIFICS, DefaultBookmarkSpecifics());
4219 perm_folder.Put(IS_UNSYNCED, true); 4220 perm_folder.Put(IS_UNSYNCED, true);
4220 perm_folder.Put(IS_DEL, true); 4221 perm_folder.Put(IS_DEL, true);
4221 } 4222 }
4222 4223
4223 mock_server_->AddUpdateDirectory(1, 0, "permitem_renamed", 10, 100); 4224 mock_server_->AddUpdateDirectory(1, 0, "permitem_renamed", 10, 100);
4224 mock_server_->SetLastUpdateClientTag("clientperm"); 4225 mock_server_->SetLastUpdateClientTag("clientperm");
4225 mock_server_->set_conflict_all_commits(true); 4226 mock_server_->set_conflict_all_commits(true);
4226 4227
4227 SyncShareAsDelegate(); 4228 SyncShareAsDelegate();
4228 // This should cause client tag overwrite. 4229 // This should cause client tag overwrite.
4229 { 4230 {
4230 ReadTransaction trans(dir, __FILE__, __LINE__); 4231 ReadTransaction trans(dir, FROM_HERE);
4231 4232
4232 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "clientperm"); 4233 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "clientperm");
4233 ASSERT_TRUE(perm_folder.good()); 4234 ASSERT_TRUE(perm_folder.good());
4234 ASSERT_TRUE(perm_folder.Get(ID).ServerKnows()); 4235 ASSERT_TRUE(perm_folder.Get(ID).ServerKnows());
4235 EXPECT_TRUE(perm_folder.Get(IS_DEL)); 4236 EXPECT_TRUE(perm_folder.Get(IS_DEL));
4236 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); 4237 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE));
4237 EXPECT_TRUE(perm_folder.Get(IS_UNSYNCED)); 4238 EXPECT_TRUE(perm_folder.Get(IS_UNSYNCED));
4238 EXPECT_EQ(perm_folder.Get(BASE_VERSION), 10); 4239 EXPECT_EQ(perm_folder.Get(BASE_VERSION), 10);
4239 EXPECT_EQ(perm_folder.Get(UNIQUE_CLIENT_TAG), "clientperm"); 4240 EXPECT_EQ(perm_folder.Get(UNIQUE_CLIENT_TAG), "clientperm");
4240 } 4241 }
(...skipping 13 matching lines...) Expand all
4254 mock_server_->AddUpdateBookmark(4, 0, "Four", 11, 110); 4255 mock_server_->AddUpdateBookmark(4, 0, "Four", 11, 110);
4255 mock_server_->SetLastUpdateClientTag("tag2"); 4256 mock_server_->SetLastUpdateClientTag("tag2");
4256 4257
4257 mock_server_->set_conflict_all_commits(true); 4258 mock_server_->set_conflict_all_commits(true);
4258 4259
4259 SyncShareAsDelegate(); 4260 SyncShareAsDelegate();
4260 int64 tag1_metahandle = syncable::kInvalidMetaHandle; 4261 int64 tag1_metahandle = syncable::kInvalidMetaHandle;
4261 int64 tag2_metahandle = syncable::kInvalidMetaHandle; 4262 int64 tag2_metahandle = syncable::kInvalidMetaHandle;
4262 // This should cause client tag overwrite. 4263 // This should cause client tag overwrite.
4263 { 4264 {
4264 ReadTransaction trans(dir, __FILE__, __LINE__); 4265 ReadTransaction trans(dir, FROM_HERE);
4265 4266
4266 Entry tag1(&trans, GET_BY_CLIENT_TAG, "tag1"); 4267 Entry tag1(&trans, GET_BY_CLIENT_TAG, "tag1");
4267 ASSERT_TRUE(tag1.good()); 4268 ASSERT_TRUE(tag1.good());
4268 ASSERT_TRUE(tag1.Get(ID).ServerKnows()); 4269 ASSERT_TRUE(tag1.Get(ID).ServerKnows());
4269 ASSERT_TRUE(ids_.FromNumber(1) == tag1.Get(ID)); 4270 ASSERT_TRUE(ids_.FromNumber(1) == tag1.Get(ID));
4270 EXPECT_FALSE(tag1.Get(IS_DEL)); 4271 EXPECT_FALSE(tag1.Get(IS_DEL));
4271 EXPECT_FALSE(tag1.Get(IS_UNAPPLIED_UPDATE)); 4272 EXPECT_FALSE(tag1.Get(IS_UNAPPLIED_UPDATE));
4272 EXPECT_FALSE(tag1.Get(IS_UNSYNCED)); 4273 EXPECT_FALSE(tag1.Get(IS_UNSYNCED));
4273 EXPECT_EQ("One", tag1.Get(NON_UNIQUE_NAME)); 4274 EXPECT_EQ("One", tag1.Get(NON_UNIQUE_NAME));
4274 EXPECT_EQ(10, tag1.Get(BASE_VERSION)); 4275 EXPECT_EQ(10, tag1.Get(BASE_VERSION));
(...skipping 17 matching lines...) Expand all
4292 ASSERT_EQ(2U, children.size()); 4293 ASSERT_EQ(2U, children.size());
4293 } 4294 }
4294 4295
4295 mock_server_->AddUpdateBookmark(2, 0, "Two", 12, 120); 4296 mock_server_->AddUpdateBookmark(2, 0, "Two", 12, 120);
4296 mock_server_->SetLastUpdateClientTag("tag1"); 4297 mock_server_->SetLastUpdateClientTag("tag1");
4297 mock_server_->AddUpdateBookmark(3, 0, "Three", 13, 130); 4298 mock_server_->AddUpdateBookmark(3, 0, "Three", 13, 130);
4298 mock_server_->SetLastUpdateClientTag("tag2"); 4299 mock_server_->SetLastUpdateClientTag("tag2");
4299 SyncShareAsDelegate(); 4300 SyncShareAsDelegate();
4300 4301
4301 { 4302 {
4302 ReadTransaction trans(dir, __FILE__, __LINE__); 4303 ReadTransaction trans(dir, FROM_HERE);
4303 4304
4304 Entry tag1(&trans, GET_BY_CLIENT_TAG, "tag1"); 4305 Entry tag1(&trans, GET_BY_CLIENT_TAG, "tag1");
4305 ASSERT_TRUE(tag1.good()); 4306 ASSERT_TRUE(tag1.good());
4306 ASSERT_TRUE(tag1.Get(ID).ServerKnows()); 4307 ASSERT_TRUE(tag1.Get(ID).ServerKnows());
4307 ASSERT_TRUE(ids_.FromNumber(1) == tag1.Get(ID)) 4308 ASSERT_TRUE(ids_.FromNumber(1) == tag1.Get(ID))
4308 << "ID 1 should be kept, since it was less than ID 2."; 4309 << "ID 1 should be kept, since it was less than ID 2.";
4309 EXPECT_FALSE(tag1.Get(IS_DEL)); 4310 EXPECT_FALSE(tag1.Get(IS_DEL));
4310 EXPECT_FALSE(tag1.Get(IS_UNAPPLIED_UPDATE)); 4311 EXPECT_FALSE(tag1.Get(IS_UNAPPLIED_UPDATE));
4311 EXPECT_FALSE(tag1.Get(IS_UNSYNCED)); 4312 EXPECT_FALSE(tag1.Get(IS_UNSYNCED));
4312 EXPECT_EQ(10, tag1.Get(BASE_VERSION)); 4313 EXPECT_EQ(10, tag1.Get(BASE_VERSION));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
4367 mock_server_->AddUpdateBookmark(204, 0, "Three C", 20, 200); 4368 mock_server_->AddUpdateBookmark(204, 0, "Three C", 20, 200);
4368 mock_server_->SetLastUpdateClientTag("tag c"); 4369 mock_server_->SetLastUpdateClientTag("tag c");
4369 mock_server_->AddUpdateBookmark(201, 0, "Four C", 21, 210); 4370 mock_server_->AddUpdateBookmark(201, 0, "Four C", 21, 210);
4370 mock_server_->SetLastUpdateClientTag("tag c"); // Least ID: winner. 4371 mock_server_->SetLastUpdateClientTag("tag c"); // Least ID: winner.
4371 4372
4372 mock_server_->set_conflict_all_commits(true); 4373 mock_server_->set_conflict_all_commits(true);
4373 4374
4374 SyncShareAsDelegate(); 4375 SyncShareAsDelegate();
4375 // This should cause client tag overwrite. 4376 // This should cause client tag overwrite.
4376 { 4377 {
4377 ReadTransaction trans(dir, __FILE__, __LINE__); 4378 ReadTransaction trans(dir, FROM_HERE);
4378 4379
4379 Entry tag_a(&trans, GET_BY_CLIENT_TAG, "tag a"); 4380 Entry tag_a(&trans, GET_BY_CLIENT_TAG, "tag a");
4380 ASSERT_TRUE(tag_a.good()); 4381 ASSERT_TRUE(tag_a.good());
4381 EXPECT_TRUE(tag_a.Get(ID).ServerKnows()); 4382 EXPECT_TRUE(tag_a.Get(ID).ServerKnows());
4382 EXPECT_EQ(ids_.FromNumber(1), tag_a.Get(ID)); 4383 EXPECT_EQ(ids_.FromNumber(1), tag_a.Get(ID));
4383 EXPECT_FALSE(tag_a.Get(IS_DEL)); 4384 EXPECT_FALSE(tag_a.Get(IS_DEL));
4384 EXPECT_FALSE(tag_a.Get(IS_UNAPPLIED_UPDATE)); 4385 EXPECT_FALSE(tag_a.Get(IS_UNAPPLIED_UPDATE));
4385 EXPECT_FALSE(tag_a.Get(IS_UNSYNCED)); 4386 EXPECT_FALSE(tag_a.Get(IS_UNSYNCED));
4386 EXPECT_EQ("One A", tag_a.Get(NON_UNIQUE_NAME)); 4387 EXPECT_EQ("One A", tag_a.Get(NON_UNIQUE_NAME));
4387 EXPECT_EQ(1, tag_a.Get(BASE_VERSION)); 4388 EXPECT_EQ(1, tag_a.Get(BASE_VERSION));
(...skipping 27 matching lines...) Expand all
4415 } 4416 }
4416 } 4417 }
4417 4418
4418 TEST_F(SyncerTest, UniqueServerTagUpdates) { 4419 TEST_F(SyncerTest, UniqueServerTagUpdates) {
4419 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 4420 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
4420 EXPECT_TRUE(dir.good()); 4421 EXPECT_TRUE(dir.good());
4421 // As a hurdle, introduce an item whose name is the same as the tag value 4422 // As a hurdle, introduce an item whose name is the same as the tag value
4422 // we'll use later. 4423 // we'll use later.
4423 int64 hurdle_handle = CreateUnsyncedDirectory("bob", "id_bob"); 4424 int64 hurdle_handle = CreateUnsyncedDirectory("bob", "id_bob");
4424 { 4425 {
4425 ReadTransaction trans(dir, __FILE__, __LINE__); 4426 ReadTransaction trans(dir, FROM_HERE);
4426 Entry hurdle(&trans, GET_BY_HANDLE, hurdle_handle); 4427 Entry hurdle(&trans, GET_BY_HANDLE, hurdle_handle);
4427 ASSERT_TRUE(hurdle.good()); 4428 ASSERT_TRUE(hurdle.good());
4428 ASSERT_TRUE(!hurdle.Get(IS_DEL)); 4429 ASSERT_TRUE(!hurdle.Get(IS_DEL));
4429 ASSERT_TRUE(hurdle.Get(UNIQUE_SERVER_TAG).empty()); 4430 ASSERT_TRUE(hurdle.Get(UNIQUE_SERVER_TAG).empty());
4430 ASSERT_TRUE(hurdle.Get(NON_UNIQUE_NAME) == "bob"); 4431 ASSERT_TRUE(hurdle.Get(NON_UNIQUE_NAME) == "bob");
4431 4432
4432 // Try to lookup by the tagname. These should fail. 4433 // Try to lookup by the tagname. These should fail.
4433 Entry tag_alpha(&trans, GET_BY_SERVER_TAG, "alpha"); 4434 Entry tag_alpha(&trans, GET_BY_SERVER_TAG, "alpha");
4434 EXPECT_FALSE(tag_alpha.good()); 4435 EXPECT_FALSE(tag_alpha.good());
4435 Entry tag_bob(&trans, GET_BY_SERVER_TAG, "bob"); 4436 Entry tag_bob(&trans, GET_BY_SERVER_TAG, "bob");
4436 EXPECT_FALSE(tag_bob.good()); 4437 EXPECT_FALSE(tag_bob.good());
4437 } 4438 }
4438 4439
4439 // Now download some tagged items as updates. 4440 // Now download some tagged items as updates.
4440 mock_server_->AddUpdateDirectory(1, 0, "update1", 1, 10); 4441 mock_server_->AddUpdateDirectory(1, 0, "update1", 1, 10);
4441 mock_server_->SetLastUpdateServerTag("alpha"); 4442 mock_server_->SetLastUpdateServerTag("alpha");
4442 mock_server_->AddUpdateDirectory(2, 0, "update2", 2, 20); 4443 mock_server_->AddUpdateDirectory(2, 0, "update2", 2, 20);
4443 mock_server_->SetLastUpdateServerTag("bob"); 4444 mock_server_->SetLastUpdateServerTag("bob");
4444 SyncShareAsDelegate(); 4445 SyncShareAsDelegate();
4445 4446
4446 { 4447 {
4447 ReadTransaction trans(dir, __FILE__, __LINE__); 4448 ReadTransaction trans(dir, FROM_HERE);
4448 4449
4449 // The new items should be applied as new entries, and we should be able 4450 // The new items should be applied as new entries, and we should be able
4450 // to look them up by their tag values. 4451 // to look them up by their tag values.
4451 Entry tag_alpha(&trans, GET_BY_SERVER_TAG, "alpha"); 4452 Entry tag_alpha(&trans, GET_BY_SERVER_TAG, "alpha");
4452 ASSERT_TRUE(tag_alpha.good()); 4453 ASSERT_TRUE(tag_alpha.good());
4453 ASSERT_TRUE(!tag_alpha.Get(IS_DEL)); 4454 ASSERT_TRUE(!tag_alpha.Get(IS_DEL));
4454 ASSERT_TRUE(tag_alpha.Get(UNIQUE_SERVER_TAG) == "alpha"); 4455 ASSERT_TRUE(tag_alpha.Get(UNIQUE_SERVER_TAG) == "alpha");
4455 ASSERT_TRUE(tag_alpha.Get(NON_UNIQUE_NAME) == "update1"); 4456 ASSERT_TRUE(tag_alpha.Get(NON_UNIQUE_NAME) == "update1");
4456 Entry tag_bob(&trans, GET_BY_SERVER_TAG, "bob"); 4457 Entry tag_bob(&trans, GET_BY_SERVER_TAG, "bob");
4457 ASSERT_TRUE(tag_bob.good()); 4458 ASSERT_TRUE(tag_bob.good());
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
4519 class SyncerUndeletionTest : public SyncerTest { 4520 class SyncerUndeletionTest : public SyncerTest {
4520 public: 4521 public:
4521 SyncerUndeletionTest() 4522 SyncerUndeletionTest()
4522 : client_tag_("foobar"), 4523 : client_tag_("foobar"),
4523 metahandle_(syncable::kInvalidMetaHandle) { 4524 metahandle_(syncable::kInvalidMetaHandle) {
4524 } 4525 }
4525 4526
4526 void Create() { 4527 void Create() {
4527 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 4528 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
4528 EXPECT_TRUE(dir.good()); 4529 EXPECT_TRUE(dir.good());
4529 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 4530 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
4530 MutableEntry perm_folder(&trans, CREATE, ids_.root(), "clientname"); 4531 MutableEntry perm_folder(&trans, CREATE, ids_.root(), "clientname");
4531 ASSERT_TRUE(perm_folder.good()); 4532 ASSERT_TRUE(perm_folder.good());
4532 perm_folder.Put(UNIQUE_CLIENT_TAG, client_tag_); 4533 perm_folder.Put(UNIQUE_CLIENT_TAG, client_tag_);
4533 perm_folder.Put(IS_UNSYNCED, true); 4534 perm_folder.Put(IS_UNSYNCED, true);
4534 perm_folder.Put(SYNCING, false); 4535 perm_folder.Put(SYNCING, false);
4535 perm_folder.Put(SPECIFICS, DefaultBookmarkSpecifics()); 4536 perm_folder.Put(SPECIFICS, DefaultBookmarkSpecifics());
4536 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); 4537 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE));
4537 EXPECT_FALSE(perm_folder.Get(ID).ServerKnows()); 4538 EXPECT_FALSE(perm_folder.Get(ID).ServerKnows());
4538 metahandle_ = perm_folder.Get(META_HANDLE); 4539 metahandle_ = perm_folder.Get(META_HANDLE);
4539 } 4540 }
4540 4541
4541 void Delete() { 4542 void Delete() {
4542 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 4543 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
4543 EXPECT_TRUE(dir.good()); 4544 EXPECT_TRUE(dir.good());
4544 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 4545 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
4545 MutableEntry entry(&trans, GET_BY_CLIENT_TAG, client_tag_); 4546 MutableEntry entry(&trans, GET_BY_CLIENT_TAG, client_tag_);
4546 ASSERT_TRUE(entry.good()); 4547 ASSERT_TRUE(entry.good());
4547 EXPECT_EQ(metahandle_, entry.Get(META_HANDLE)); 4548 EXPECT_EQ(metahandle_, entry.Get(META_HANDLE));
4548 entry.Put(IS_DEL, true); 4549 entry.Put(IS_DEL, true);
4549 entry.Put(IS_UNSYNCED, true); 4550 entry.Put(IS_UNSYNCED, true);
4550 entry.Put(SYNCING, false); 4551 entry.Put(SYNCING, false);
4551 } 4552 }
4552 4553
4553 void Undelete() { 4554 void Undelete() {
4554 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 4555 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
4555 EXPECT_TRUE(dir.good()); 4556 EXPECT_TRUE(dir.good());
4556 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 4557 WriteTransaction trans(dir, UNITTEST, FROM_HERE);
4557 MutableEntry entry(&trans, GET_BY_CLIENT_TAG, client_tag_); 4558 MutableEntry entry(&trans, GET_BY_CLIENT_TAG, client_tag_);
4558 ASSERT_TRUE(entry.good()); 4559 ASSERT_TRUE(entry.good());
4559 EXPECT_EQ(metahandle_, entry.Get(META_HANDLE)); 4560 EXPECT_EQ(metahandle_, entry.Get(META_HANDLE));
4560 EXPECT_TRUE(entry.Get(IS_DEL)); 4561 EXPECT_TRUE(entry.Get(IS_DEL));
4561 entry.Put(IS_DEL, false); 4562 entry.Put(IS_DEL, false);
4562 entry.Put(IS_UNSYNCED, true); 4563 entry.Put(IS_UNSYNCED, true);
4563 entry.Put(SYNCING, false); 4564 entry.Put(SYNCING, false);
4564 } 4565 }
4565 4566
4566 int64 GetMetahandleOfTag() { 4567 int64 GetMetahandleOfTag() {
4567 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 4568 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
4568 EXPECT_TRUE(dir.good()); 4569 EXPECT_TRUE(dir.good());
4569 ReadTransaction trans(dir, __FILE__, __LINE__); 4570 ReadTransaction trans(dir, FROM_HERE);
4570 Entry entry(&trans, GET_BY_CLIENT_TAG, client_tag_); 4571 Entry entry(&trans, GET_BY_CLIENT_TAG, client_tag_);
4571 EXPECT_TRUE(entry.good()); 4572 EXPECT_TRUE(entry.good());
4572 if (!entry.good()) { 4573 if (!entry.good()) {
4573 return syncable::kInvalidMetaHandle; 4574 return syncable::kInvalidMetaHandle;
4574 } 4575 }
4575 return entry.Get(META_HANDLE); 4576 return entry.Get(META_HANDLE);
4576 } 4577 }
4577 4578
4578 void ExpectUnsyncedCreation() { 4579 void ExpectUnsyncedCreation() {
4579 EXPECT_EQ(metahandle_, GetMetahandleOfTag()); 4580 EXPECT_EQ(metahandle_, GetMetahandleOfTag());
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
4968 public: 4969 public:
4969 SyncerPositionUpdateTest() : next_update_id_(1), next_revision_(1) {} 4970 SyncerPositionUpdateTest() : next_update_id_(1), next_revision_(1) {}
4970 4971
4971 protected: 4972 protected:
4972 void ExpectLocalItemsInServerOrder() { 4973 void ExpectLocalItemsInServerOrder() {
4973 if (position_map_.empty()) 4974 if (position_map_.empty())
4974 return; 4975 return;
4975 4976
4976 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 4977 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
4977 EXPECT_TRUE(dir.good()); 4978 EXPECT_TRUE(dir.good());
4978 ReadTransaction trans(dir, __FILE__, __LINE__); 4979 ReadTransaction trans(dir, FROM_HERE);
4979 4980
4980 Id prev_id; 4981 Id prev_id;
4981 DCHECK(prev_id.IsRoot()); 4982 DCHECK(prev_id.IsRoot());
4982 PosMap::iterator next = position_map_.begin(); 4983 PosMap::iterator next = position_map_.begin();
4983 for (PosMap::iterator i = next++; i != position_map_.end(); ++i) { 4984 for (PosMap::iterator i = next++; i != position_map_.end(); ++i) {
4984 Id id = i->second; 4985 Id id = i->second;
4985 Entry entry_with_id(&trans, GET_BY_ID, id); 4986 Entry entry_with_id(&trans, GET_BY_ID, id);
4986 EXPECT_TRUE(entry_with_id.good()); 4987 EXPECT_TRUE(entry_with_id.good());
4987 EXPECT_EQ(prev_id, entry_with_id.Get(PREV_ID)); 4988 EXPECT_EQ(prev_id, entry_with_id.Get(PREV_ID));
4988 EXPECT_EQ(i->first, entry_with_id.Get(SERVER_POSITION_IN_PARENT)); 4989 EXPECT_EQ(i->first, entry_with_id.Get(SERVER_POSITION_IN_PARENT));
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
5096 int revision = next_revision_++; 5097 int revision = next_revision_++;
5097 mock_server_->AddUpdateDirectory(id.GetServerId(), kRootId, 5098 mock_server_->AddUpdateDirectory(id.GetServerId(), kRootId,
5098 id.GetServerId(), revision, revision); 5099 id.GetServerId(), revision, revision);
5099 // The update position doesn't vary. 5100 // The update position doesn't vary.
5100 mock_server_->SetLastUpdatePosition(90210); 5101 mock_server_->SetLastUpdatePosition(90210);
5101 } 5102 }
5102 5103
5103 void ExpectLocalOrderIsByServerId() { 5104 void ExpectLocalOrderIsByServerId() {
5104 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 5105 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
5105 EXPECT_TRUE(dir.good()); 5106 EXPECT_TRUE(dir.good());
5106 ReadTransaction trans(dir, __FILE__, __LINE__); 5107 ReadTransaction trans(dir, FROM_HERE);
5107 Id null_id; 5108 Id null_id;
5108 Entry low(&trans, GET_BY_ID, low_id_); 5109 Entry low(&trans, GET_BY_ID, low_id_);
5109 Entry mid(&trans, GET_BY_ID, mid_id_); 5110 Entry mid(&trans, GET_BY_ID, mid_id_);
5110 Entry high(&trans, GET_BY_ID, high_id_); 5111 Entry high(&trans, GET_BY_ID, high_id_);
5111 EXPECT_TRUE(low.good()); 5112 EXPECT_TRUE(low.good());
5112 EXPECT_TRUE(mid.good()); 5113 EXPECT_TRUE(mid.good());
5113 EXPECT_TRUE(high.good()); 5114 EXPECT_TRUE(high.good());
5114 EXPECT_TRUE(low.Get(PREV_ID) == null_id); 5115 EXPECT_TRUE(low.Get(PREV_ID) == null_id);
5115 EXPECT_TRUE(mid.Get(PREV_ID) == low_id_); 5116 EXPECT_TRUE(mid.Get(PREV_ID) == low_id_);
5116 EXPECT_TRUE(high.Get(PREV_ID) == mid_id_); 5117 EXPECT_TRUE(high.Get(PREV_ID) == mid_id_);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
5177 Add(low_id_); 5178 Add(low_id_);
5178 Add(high_id_); 5179 Add(high_id_);
5179 SyncShareAsDelegate(); 5180 SyncShareAsDelegate();
5180 ExpectLocalOrderIsByServerId(); 5181 ExpectLocalOrderIsByServerId();
5181 } 5182 }
5182 5183
5183 const SyncerTest::CommitOrderingTest 5184 const SyncerTest::CommitOrderingTest
5184 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; 5185 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()};
5185 5186
5186 } // namespace browser_sync 5187 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/syncer.cc ('k') | chrome/browser/sync/engine/syncer_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698