| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 entry. | 3 // found in the LICENSE entry. |
| 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 <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> |
| 11 | 12 |
| 12 #include "base/at_exit.h" | 13 #include "base/at_exit.h" |
| 13 | 14 |
| 14 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
| 15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 16 #include "chrome/browser/sync/engine/conflict_resolver.h" | 17 #include "chrome/browser/sync/engine/conflict_resolver.h" |
| 17 #include "chrome/browser/sync/engine/get_commit_ids_command.h" | 18 #include "chrome/browser/sync/engine/get_commit_ids_command.h" |
| 18 #include "chrome/browser/sync/engine/model_safe_worker.h" | 19 #include "chrome/browser/sync/engine/model_safe_worker.h" |
| 19 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 20 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
| 20 #include "chrome/browser/sync/engine/process_updates_command.h" | 21 #include "chrome/browser/sync/engine/process_updates_command.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 mock_server_.reset(); | 182 mock_server_.reset(); |
| 182 hookup_.reset(); | 183 hookup_.reset(); |
| 183 delete syncer_; | 184 delete syncer_; |
| 184 syncer_ = NULL; | 185 syncer_ = NULL; |
| 185 syncdb_.TearDown(); | 186 syncdb_.TearDown(); |
| 186 } | 187 } |
| 187 void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) { | 188 void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) { |
| 188 EXPECT_FALSE(entry->Get(IS_DIR)); | 189 EXPECT_FALSE(entry->Get(IS_DIR)); |
| 189 EXPECT_FALSE(entry->Get(IS_DEL)); | 190 EXPECT_FALSE(entry->Get(IS_DEL)); |
| 190 Blob test_value(kTestData, kTestData + kTestDataLen); | 191 Blob test_value(kTestData, kTestData + kTestDataLen); |
| 191 ExtendedAttributeKey key(entry->Get(META_HANDLE), PSTR("DATA")); | 192 ExtendedAttributeKey key(entry->Get(META_HANDLE), "DATA"); |
| 192 MutableExtendedAttribute attr(trans, CREATE, key); | 193 MutableExtendedAttribute attr(trans, CREATE, key); |
| 193 attr.mutable_value()->swap(test_value); | 194 attr.mutable_value()->swap(test_value); |
| 194 entry->Put(syncable::IS_UNSYNCED, true); | 195 entry->Put(syncable::IS_UNSYNCED, true); |
| 195 } | 196 } |
| 196 void VerifyTestDataInEntry(BaseTransaction* trans, Entry* entry) { | 197 void VerifyTestDataInEntry(BaseTransaction* trans, Entry* entry) { |
| 197 EXPECT_FALSE(entry->Get(IS_DIR)); | 198 EXPECT_FALSE(entry->Get(IS_DIR)); |
| 198 EXPECT_FALSE(entry->Get(IS_DEL)); | 199 EXPECT_FALSE(entry->Get(IS_DEL)); |
| 199 Blob test_value(kTestData, kTestData + kTestDataLen); | 200 Blob test_value(kTestData, kTestData + kTestDataLen); |
| 200 ExtendedAttributeKey key(entry->Get(META_HANDLE), PSTR("DATA")); | 201 ExtendedAttributeKey key(entry->Get(META_HANDLE), "DATA"); |
| 201 ExtendedAttribute attr(trans, GET_BY_HANDLE, key); | 202 ExtendedAttribute attr(trans, GET_BY_HANDLE, key); |
| 202 EXPECT_FALSE(attr.is_deleted()); | 203 EXPECT_FALSE(attr.is_deleted()); |
| 203 EXPECT_TRUE(test_value == attr.value()); | 204 EXPECT_TRUE(test_value == attr.value()); |
| 204 } | 205 } |
| 205 void SyncRepeatedlyToTriggerConflictResolution(SyncSession* session) { | 206 void SyncRepeatedlyToTriggerConflictResolution(SyncSession* session) { |
| 206 // We should trigger after less than 6 syncs, but extra does no harm. | 207 // We should trigger after less than 6 syncs, but extra does no harm. |
| 207 for (int i = 0 ; i < 6 ; ++i) | 208 for (int i = 0 ; i < 6 ; ++i) |
| 208 syncer_->SyncShare(session); | 209 syncer_->SyncShare(session); |
| 209 } | 210 } |
| 210 void SyncRepeatedlyToTriggerStuckSignal(SyncSession* session) { | 211 void SyncRepeatedlyToTriggerStuckSignal(SyncSession* session) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 241 { // Transaction scope. | 242 { // Transaction scope. |
| 242 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 243 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 243 while (!test->id.IsRoot()) { | 244 while (!test->id.IsRoot()) { |
| 244 if (test->commit_index >= 0) { | 245 if (test->commit_index >= 0) { |
| 245 map<int, syncable::Id>::value_type entry(test->commit_index, | 246 map<int, syncable::Id>::value_type entry(test->commit_index, |
| 246 test->id); | 247 test->id); |
| 247 bool double_position = !expected_positions.insert(entry).second; | 248 bool double_position = !expected_positions.insert(entry).second; |
| 248 ASSERT_FALSE(double_position) << "Two id's expected at one position"; | 249 ASSERT_FALSE(double_position) << "Two id's expected at one position"; |
| 249 } | 250 } |
| 250 string utf8_name = test->id.GetServerId(); | 251 string utf8_name = test->id.GetServerId(); |
| 251 PathString name(utf8_name.begin(), utf8_name.end()); | 252 string name(utf8_name.begin(), utf8_name.end()); |
| 252 MutableEntry entry(&trans, CREATE, test->parent_id, name); | 253 MutableEntry entry(&trans, CREATE, test->parent_id, name); |
| 253 entry.Put(syncable::ID, test->id); | 254 entry.Put(syncable::ID, test->id); |
| 254 if (test->id.ServerKnows()) { | 255 if (test->id.ServerKnows()) { |
| 255 entry.Put(BASE_VERSION, 5); | 256 entry.Put(BASE_VERSION, 5); |
| 256 entry.Put(SERVER_VERSION, 5); | 257 entry.Put(SERVER_VERSION, 5); |
| 257 entry.Put(SERVER_PARENT_ID, test->parent_id); | 258 entry.Put(SERVER_PARENT_ID, test->parent_id); |
| 258 } | 259 } |
| 259 entry.Put(syncable::IS_DIR, true); | 260 entry.Put(syncable::IS_DIR, true); |
| 260 entry.Put(syncable::IS_UNSYNCED, true); | 261 entry.Put(syncable::IS_UNSYNCED, true); |
| 261 // Set the time to 30 seconds in the future to reduce the chance of | 262 // Set the time to 30 seconds in the future to reduce the chance of |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 vector<syncable::Id> output = command.ordered_commit_set_.GetCommitIds(); | 315 vector<syncable::Id> output = command.ordered_commit_set_.GetCommitIds(); |
| 315 size_t truncated_size = std::min(limit, expected_id_order.size()); | 316 size_t truncated_size = std::min(limit, expected_id_order.size()); |
| 316 ASSERT_TRUE(truncated_size == output.size()); | 317 ASSERT_TRUE(truncated_size == output.size()); |
| 317 for (size_t i = 0; i < truncated_size; ++i) { | 318 for (size_t i = 0; i < truncated_size; ++i) { |
| 318 ASSERT_TRUE(expected_id_order[i] == output[i]) | 319 ASSERT_TRUE(expected_id_order[i] == output[i]) |
| 319 << "At index " << i << " with batch size limited to " << limit; | 320 << "At index " << i << " with batch size limited to " << limit; |
| 320 } | 321 } |
| 321 } | 322 } |
| 322 } | 323 } |
| 323 | 324 |
| 324 int64 CreateUnsyncedDirectory(const PathString& entry_name, | 325 int64 CreateUnsyncedDirectory(const string& entry_name, |
| 325 const string& idstring) { | 326 const string& idstring) { |
| 326 return CreateUnsyncedDirectory(entry_name, | 327 return CreateUnsyncedDirectory(entry_name, |
| 327 syncable::Id::CreateFromServerId(idstring)); | 328 syncable::Id::CreateFromServerId(idstring)); |
| 328 } | 329 } |
| 329 | 330 |
| 330 int64 CreateUnsyncedDirectory(const PathString& entry_name, | 331 int64 CreateUnsyncedDirectory(const string& entry_name, |
| 331 const syncable::Id& id) { | 332 const syncable::Id& id) { |
| 332 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 333 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 333 EXPECT_TRUE(dir.good()); | 334 EXPECT_TRUE(dir.good()); |
| 334 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 335 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 335 MutableEntry entry(&wtrans, syncable::CREATE, wtrans.root_id(), | 336 MutableEntry entry(&wtrans, syncable::CREATE, wtrans.root_id(), |
| 336 entry_name); | 337 entry_name); |
| 337 EXPECT_TRUE(entry.good()); | 338 EXPECT_TRUE(entry.good()); |
| 338 entry.Put(syncable::IS_UNSYNCED, true); | 339 entry.Put(syncable::IS_UNSYNCED, true); |
| 339 entry.Put(syncable::IS_DIR, true); | 340 entry.Put(syncable::IS_DIR, true); |
| 340 entry.Put(syncable::BASE_VERSION, id.ServerKnows() ? 1 : 0); | 341 entry.Put(syncable::BASE_VERSION, id.ServerKnows() ? 1 : 0); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 ASSERT_TRUE(0 == handles.size()); | 380 ASSERT_TRUE(0 == handles.size()); |
| 380 } | 381 } |
| 381 // TODO(sync): When we can dynamically connect and disconnect the mock | 382 // TODO(sync): When we can dynamically connect and disconnect the mock |
| 382 // ServerConnectionManager test disconnected GetUnsyncedEntries here. It's a | 383 // ServerConnectionManager test disconnected GetUnsyncedEntries here. It's a |
| 383 // regression for a very old bug. | 384 // regression for a very old bug. |
| 384 } | 385 } |
| 385 | 386 |
| 386 TEST_F(SyncerTest, GetCommitIdsCommandTruncates) { | 387 TEST_F(SyncerTest, GetCommitIdsCommandTruncates) { |
| 387 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 388 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 388 ASSERT_TRUE(dir.good()); | 389 ASSERT_TRUE(dir.good()); |
| 389 int64 handle_c = CreateUnsyncedDirectory(PSTR("C"), ids_.MakeLocal("c")); | 390 int64 handle_c = CreateUnsyncedDirectory("C", ids_.MakeLocal("c")); |
| 390 int64 handle_x = CreateUnsyncedDirectory(PSTR("X"), ids_.MakeLocal("x")); | 391 int64 handle_x = CreateUnsyncedDirectory("X", ids_.MakeLocal("x")); |
| 391 int64 handle_b = CreateUnsyncedDirectory(PSTR("B"), ids_.MakeLocal("b")); | 392 int64 handle_b = CreateUnsyncedDirectory("B", ids_.MakeLocal("b")); |
| 392 int64 handle_d = CreateUnsyncedDirectory(PSTR("D"), ids_.MakeLocal("d")); | 393 int64 handle_d = CreateUnsyncedDirectory("D", ids_.MakeLocal("d")); |
| 393 int64 handle_e = CreateUnsyncedDirectory(PSTR("E"), ids_.MakeLocal("e")); | 394 int64 handle_e = CreateUnsyncedDirectory("E", ids_.MakeLocal("e")); |
| 394 { | 395 { |
| 395 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 396 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 396 MutableEntry entry_x(&wtrans, GET_BY_HANDLE, handle_x); | 397 MutableEntry entry_x(&wtrans, GET_BY_HANDLE, handle_x); |
| 397 MutableEntry entry_b(&wtrans, GET_BY_HANDLE, handle_b); | 398 MutableEntry entry_b(&wtrans, GET_BY_HANDLE, handle_b); |
| 398 MutableEntry entry_c(&wtrans, GET_BY_HANDLE, handle_c); | 399 MutableEntry entry_c(&wtrans, GET_BY_HANDLE, handle_c); |
| 399 MutableEntry entry_d(&wtrans, GET_BY_HANDLE, handle_d); | 400 MutableEntry entry_d(&wtrans, GET_BY_HANDLE, handle_d); |
| 400 MutableEntry entry_e(&wtrans, GET_BY_HANDLE, handle_e); | 401 MutableEntry entry_e(&wtrans, GET_BY_HANDLE, handle_e); |
| 401 entry_x.Put(IS_BOOKMARK_OBJECT, true); | 402 entry_x.Put(IS_BOOKMARK_OBJECT, true); |
| 402 entry_b.Put(IS_BOOKMARK_OBJECT, true); | 403 entry_b.Put(IS_BOOKMARK_OBJECT, true); |
| 403 entry_c.Put(IS_BOOKMARK_OBJECT, true); | 404 entry_c.Put(IS_BOOKMARK_OBJECT, true); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 | 436 |
| 436 GetCommitIdsCommand::OrderedCommitSet commit_set; | 437 GetCommitIdsCommand::OrderedCommitSet commit_set; |
| 437 GetCommitIdsCommand::CommitMetahandleIterator iterator(unsynced, &wtrans, | 438 GetCommitIdsCommand::CommitMetahandleIterator iterator(unsynced, &wtrans, |
| 438 &commit_set); | 439 &commit_set); |
| 439 EXPECT_FALSE(iterator.Valid()); | 440 EXPECT_FALSE(iterator.Valid()); |
| 440 EXPECT_FALSE(iterator.Increment()); | 441 EXPECT_FALSE(iterator.Increment()); |
| 441 } | 442 } |
| 442 | 443 |
| 443 { | 444 { |
| 444 vector<int64> session_metahandles; | 445 vector<int64> session_metahandles; |
| 445 session_metahandles.push_back( | 446 session_metahandles.push_back(CreateUnsyncedDirectory("test1", "testid1")); |
| 446 CreateUnsyncedDirectory(PSTR("test1"), "testid1")); | 447 session_metahandles.push_back(CreateUnsyncedDirectory("test2", "testid2")); |
| 447 session_metahandles.push_back( | 448 session_metahandles.push_back(CreateUnsyncedDirectory("test3", "testid3")); |
| 448 CreateUnsyncedDirectory(PSTR("test2"), "testid2")); | |
| 449 session_metahandles.push_back( | |
| 450 CreateUnsyncedDirectory(PSTR("test3"), "testid3")); | |
| 451 status->set_unsynced_handles(session_metahandles); | 449 status->set_unsynced_handles(session_metahandles); |
| 452 | 450 |
| 453 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 451 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 454 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans); | 452 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans); |
| 455 GetCommitIdsCommand::OrderedCommitSet commit_set; | 453 GetCommitIdsCommand::OrderedCommitSet commit_set; |
| 456 GetCommitIdsCommand::CommitMetahandleIterator iterator(unsynced, &wtrans, | 454 GetCommitIdsCommand::CommitMetahandleIterator iterator(unsynced, &wtrans, |
| 457 &commit_set); | 455 &commit_set); |
| 458 | 456 |
| 459 EXPECT_TRUE(iterator.Valid()); | 457 EXPECT_TRUE(iterator.Valid()); |
| 460 EXPECT_TRUE(iterator.Current() == session_metahandles[0]); | 458 EXPECT_TRUE(iterator.Current() == session_metahandles[0]); |
| 461 EXPECT_TRUE(iterator.Increment()); | 459 EXPECT_TRUE(iterator.Increment()); |
| 462 | 460 |
| 463 EXPECT_TRUE(iterator.Valid()); | 461 EXPECT_TRUE(iterator.Valid()); |
| 464 EXPECT_TRUE(iterator.Current() == session_metahandles[1]); | 462 EXPECT_TRUE(iterator.Current() == session_metahandles[1]); |
| 465 EXPECT_TRUE(iterator.Increment()); | 463 EXPECT_TRUE(iterator.Increment()); |
| 466 | 464 |
| 467 EXPECT_TRUE(iterator.Valid()); | 465 EXPECT_TRUE(iterator.Valid()); |
| 468 EXPECT_TRUE(iterator.Current() == session_metahandles[2]); | 466 EXPECT_TRUE(iterator.Current() == session_metahandles[2]); |
| 469 EXPECT_FALSE(iterator.Increment()); | 467 EXPECT_FALSE(iterator.Increment()); |
| 470 | 468 |
| 471 EXPECT_FALSE(iterator.Valid()); | 469 EXPECT_FALSE(iterator.Valid()); |
| 472 } | 470 } |
| 473 } | 471 } |
| 474 | 472 |
| 475 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) { | 473 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) { |
| 476 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 474 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 477 ASSERT_TRUE(dir.good()); | 475 ASSERT_TRUE(dir.good()); |
| 478 PathString xattr_key = PSTR("key"); | 476 string xattr_key = "key"; |
| 479 { | 477 { |
| 480 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 478 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 481 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), | 479 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), |
| 482 PSTR("Pete")); | 480 "Pete"); |
| 483 ASSERT_TRUE(parent.good()); | 481 ASSERT_TRUE(parent.good()); |
| 484 parent.Put(syncable::IS_UNSYNCED, true); | 482 parent.Put(syncable::IS_UNSYNCED, true); |
| 485 parent.Put(syncable::IS_DIR, true); | 483 parent.Put(syncable::IS_DIR, true); |
| 486 parent.Put(syncable::BASE_VERSION, 1); | 484 parent.Put(syncable::BASE_VERSION, 1); |
| 487 parent.Put(syncable::ID, parent_id_); | 485 parent.Put(syncable::ID, parent_id_); |
| 488 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, PSTR("Pete")); | 486 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete"); |
| 489 ASSERT_TRUE(child.good()); | 487 ASSERT_TRUE(child.good()); |
| 490 child.Put(syncable::ID, child_id_); | 488 child.Put(syncable::ID, child_id_); |
| 491 child.Put(syncable::BASE_VERSION, 1); | 489 child.Put(syncable::BASE_VERSION, 1); |
| 492 WriteTestDataToEntry(&wtrans, &child); | 490 WriteTestDataToEntry(&wtrans, &child); |
| 493 } | 491 } |
| 494 | 492 |
| 495 StatusController* status = session_->status_controller(); | 493 StatusController* status = session_->status_controller(); |
| 496 syncer_->SyncShare(session_.get()); | 494 syncer_->SyncShare(session_.get()); |
| 497 EXPECT_TRUE(2 == status->unsynced_handles().size()); | 495 EXPECT_TRUE(2 == status->unsynced_handles().size()); |
| 498 ASSERT_TRUE(2 == mock_server_->committed_ids().size()); | 496 ASSERT_TRUE(2 == mock_server_->committed_ids().size()); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 TEST_F(SyncerTest, TestCommitListOrderingWithNesting) { | 636 TEST_F(SyncerTest, TestCommitListOrderingWithNesting) { |
| 639 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 637 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 640 ASSERT_TRUE(dir.good()); | 638 ASSERT_TRUE(dir.good()); |
| 641 int64 now_server_time = ClientTimeToServerTime(syncable::Now()); | 639 int64 now_server_time = ClientTimeToServerTime(syncable::Now()); |
| 642 int64 now_minus_2h = ServerTimeToClientTime(now_server_time - 7200000); | 640 int64 now_minus_2h = ServerTimeToClientTime(now_server_time - 7200000); |
| 643 | 641 |
| 644 { | 642 { |
| 645 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 643 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 646 { | 644 { |
| 647 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), | 645 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), |
| 648 PSTR("Bob")); | 646 "Bob"); |
| 649 ASSERT_TRUE(parent.good()); | 647 ASSERT_TRUE(parent.good()); |
| 650 parent.Put(syncable::IS_UNSYNCED, true); | 648 parent.Put(syncable::IS_UNSYNCED, true); |
| 651 parent.Put(syncable::IS_DIR, true); | 649 parent.Put(syncable::IS_DIR, true); |
| 652 parent.Put(syncable::ID, ids_.FromNumber(100)); | 650 parent.Put(syncable::ID, ids_.FromNumber(100)); |
| 653 parent.Put(syncable::BASE_VERSION, 1); | 651 parent.Put(syncable::BASE_VERSION, 1); |
| 654 MutableEntry child(&wtrans, syncable::CREATE, ids_.FromNumber(100), | 652 MutableEntry child(&wtrans, syncable::CREATE, ids_.FromNumber(100), |
| 655 PSTR("Bob")); | 653 "Bob"); |
| 656 ASSERT_TRUE(child.good()); | 654 ASSERT_TRUE(child.good()); |
| 657 child.Put(syncable::IS_UNSYNCED, true); | 655 child.Put(syncable::IS_UNSYNCED, true); |
| 658 child.Put(syncable::IS_DIR, true); | 656 child.Put(syncable::IS_DIR, true); |
| 659 child.Put(syncable::ID, ids_.FromNumber(101)); | 657 child.Put(syncable::ID, ids_.FromNumber(101)); |
| 660 child.Put(syncable::BASE_VERSION, 1); | 658 child.Put(syncable::BASE_VERSION, 1); |
| 661 MutableEntry grandchild(&wtrans, syncable::CREATE, ids_.FromNumber(101), | 659 MutableEntry grandchild(&wtrans, syncable::CREATE, ids_.FromNumber(101), |
| 662 PSTR("Bob")); | 660 "Bob"); |
| 663 ASSERT_TRUE(grandchild.good()); | 661 ASSERT_TRUE(grandchild.good()); |
| 664 grandchild.Put(syncable::ID, ids_.FromNumber(102)); | 662 grandchild.Put(syncable::ID, ids_.FromNumber(102)); |
| 665 grandchild.Put(syncable::IS_UNSYNCED, true); | 663 grandchild.Put(syncable::IS_UNSYNCED, true); |
| 666 grandchild.Put(syncable::BASE_VERSION, 1); | 664 grandchild.Put(syncable::BASE_VERSION, 1); |
| 667 } | 665 } |
| 668 { | 666 { |
| 669 // Create three deleted items which deletions we expect to be sent to the | 667 // Create three deleted items which deletions we expect to be sent to the |
| 670 // server. | 668 // server. |
| 671 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), | 669 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), |
| 672 PSTR("Pete")); | 670 "Pete"); |
| 673 ASSERT_TRUE(parent.good()); | 671 ASSERT_TRUE(parent.good()); |
| 674 parent.Put(syncable::IS_UNSYNCED, true); | 672 parent.Put(syncable::IS_UNSYNCED, true); |
| 675 parent.Put(syncable::IS_DIR, true); | 673 parent.Put(syncable::IS_DIR, true); |
| 676 parent.Put(syncable::IS_DEL, true); | 674 parent.Put(syncable::IS_DEL, true); |
| 677 parent.Put(syncable::ID, ids_.FromNumber(103)); | 675 parent.Put(syncable::ID, ids_.FromNumber(103)); |
| 678 parent.Put(syncable::BASE_VERSION, 1); | 676 parent.Put(syncable::BASE_VERSION, 1); |
| 679 parent.Put(syncable::MTIME, now_minus_2h); | 677 parent.Put(syncable::MTIME, now_minus_2h); |
| 680 MutableEntry child(&wtrans, syncable::CREATE, ids_.FromNumber(103), | 678 MutableEntry child(&wtrans, syncable::CREATE, ids_.FromNumber(103), |
| 681 PSTR("Pete")); | 679 "Pete"); |
| 682 ASSERT_TRUE(child.good()); | 680 ASSERT_TRUE(child.good()); |
| 683 child.Put(syncable::IS_UNSYNCED, true); | 681 child.Put(syncable::IS_UNSYNCED, true); |
| 684 child.Put(syncable::IS_DIR, true); | 682 child.Put(syncable::IS_DIR, true); |
| 685 child.Put(syncable::IS_DEL, true); | 683 child.Put(syncable::IS_DEL, true); |
| 686 child.Put(syncable::ID, ids_.FromNumber(104)); | 684 child.Put(syncable::ID, ids_.FromNumber(104)); |
| 687 child.Put(syncable::BASE_VERSION, 1); | 685 child.Put(syncable::BASE_VERSION, 1); |
| 688 child.Put(syncable::MTIME, now_minus_2h); | 686 child.Put(syncable::MTIME, now_minus_2h); |
| 689 MutableEntry grandchild(&wtrans, syncable::CREATE, ids_.FromNumber(104), | 687 MutableEntry grandchild(&wtrans, syncable::CREATE, ids_.FromNumber(104), |
| 690 PSTR("Pete")); | 688 "Pete"); |
| 691 ASSERT_TRUE(grandchild.good()); | 689 ASSERT_TRUE(grandchild.good()); |
| 692 grandchild.Put(syncable::IS_UNSYNCED, true); | 690 grandchild.Put(syncable::IS_UNSYNCED, true); |
| 693 grandchild.Put(syncable::ID, ids_.FromNumber(105)); | 691 grandchild.Put(syncable::ID, ids_.FromNumber(105)); |
| 694 grandchild.Put(syncable::IS_DEL, true); | 692 grandchild.Put(syncable::IS_DEL, true); |
| 695 grandchild.Put(syncable::IS_DIR, false); | 693 grandchild.Put(syncable::IS_DIR, false); |
| 696 grandchild.Put(syncable::BASE_VERSION, 1); | 694 grandchild.Put(syncable::BASE_VERSION, 1); |
| 697 grandchild.Put(syncable::MTIME, now_minus_2h); | 695 grandchild.Put(syncable::MTIME, now_minus_2h); |
| 698 } | 696 } |
| 699 } | 697 } |
| 700 | 698 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 713 EXPECT_TRUE(ids_.FromNumber(103) == commit_ids[3]); | 711 EXPECT_TRUE(ids_.FromNumber(103) == commit_ids[3]); |
| 714 EXPECT_TRUE(ids_.FromNumber(104) == commit_ids[4]); | 712 EXPECT_TRUE(ids_.FromNumber(104) == commit_ids[4]); |
| 715 EXPECT_TRUE(ids_.FromNumber(105) == commit_ids[5]); | 713 EXPECT_TRUE(ids_.FromNumber(105) == commit_ids[5]); |
| 716 } | 714 } |
| 717 | 715 |
| 718 TEST_F(SyncerTest, TestCommitListOrderingWithNewItems) { | 716 TEST_F(SyncerTest, TestCommitListOrderingWithNewItems) { |
| 719 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 717 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 720 ASSERT_TRUE(dir.good()); | 718 ASSERT_TRUE(dir.good()); |
| 721 { | 719 { |
| 722 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 720 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 723 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), PSTR("1")); | 721 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "1"); |
| 724 ASSERT_TRUE(parent.good()); | 722 ASSERT_TRUE(parent.good()); |
| 725 parent.Put(syncable::IS_UNSYNCED, true); | 723 parent.Put(syncable::IS_UNSYNCED, true); |
| 726 parent.Put(syncable::IS_DIR, true); | 724 parent.Put(syncable::IS_DIR, true); |
| 727 parent.Put(syncable::ID, parent_id_); | 725 parent.Put(syncable::ID, parent_id_); |
| 728 MutableEntry child(&wtrans, syncable::CREATE, wtrans.root_id(), PSTR("2")); | 726 MutableEntry child(&wtrans, syncable::CREATE, wtrans.root_id(), "2"); |
| 729 ASSERT_TRUE(child.good()); | 727 ASSERT_TRUE(child.good()); |
| 730 child.Put(syncable::IS_UNSYNCED, true); | 728 child.Put(syncable::IS_UNSYNCED, true); |
| 731 child.Put(syncable::IS_DIR, true); | 729 child.Put(syncable::IS_DIR, true); |
| 732 child.Put(syncable::ID, child_id_); | 730 child.Put(syncable::ID, child_id_); |
| 733 parent.Put(syncable::BASE_VERSION, 1); | 731 parent.Put(syncable::BASE_VERSION, 1); |
| 734 child.Put(syncable::BASE_VERSION, 1); | 732 child.Put(syncable::BASE_VERSION, 1); |
| 735 } | 733 } |
| 736 { | 734 { |
| 737 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 735 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 738 MutableEntry parent(&wtrans, syncable::CREATE, parent_id_, PSTR("A")); | 736 MutableEntry parent(&wtrans, syncable::CREATE, parent_id_, "A"); |
| 739 ASSERT_TRUE(parent.good()); | 737 ASSERT_TRUE(parent.good()); |
| 740 parent.Put(syncable::IS_UNSYNCED, true); | 738 parent.Put(syncable::IS_UNSYNCED, true); |
| 741 parent.Put(syncable::IS_DIR, true); | 739 parent.Put(syncable::IS_DIR, true); |
| 742 parent.Put(syncable::ID, ids_.FromNumber(102)); | 740 parent.Put(syncable::ID, ids_.FromNumber(102)); |
| 743 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, PSTR("B")); | 741 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "B"); |
| 744 ASSERT_TRUE(child.good()); | 742 ASSERT_TRUE(child.good()); |
| 745 child.Put(syncable::IS_UNSYNCED, true); | 743 child.Put(syncable::IS_UNSYNCED, true); |
| 746 child.Put(syncable::IS_DIR, true); | 744 child.Put(syncable::IS_DIR, true); |
| 747 child.Put(syncable::ID, ids_.FromNumber(-103)); | 745 child.Put(syncable::ID, ids_.FromNumber(-103)); |
| 748 parent.Put(syncable::BASE_VERSION, 1); | 746 parent.Put(syncable::BASE_VERSION, 1); |
| 749 } | 747 } |
| 750 { | 748 { |
| 751 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 749 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 752 MutableEntry parent(&wtrans, syncable::CREATE, child_id_, PSTR("A")); | 750 MutableEntry parent(&wtrans, syncable::CREATE, child_id_, "A"); |
| 753 ASSERT_TRUE(parent.good()); | 751 ASSERT_TRUE(parent.good()); |
| 754 parent.Put(syncable::IS_UNSYNCED, true); | 752 parent.Put(syncable::IS_UNSYNCED, true); |
| 755 parent.Put(syncable::IS_DIR, true); | 753 parent.Put(syncable::IS_DIR, true); |
| 756 parent.Put(syncable::ID, ids_.FromNumber(-104)); | 754 parent.Put(syncable::ID, ids_.FromNumber(-104)); |
| 757 MutableEntry child(&wtrans, syncable::CREATE, child_id_, PSTR("B")); | 755 MutableEntry child(&wtrans, syncable::CREATE, child_id_, "B"); |
| 758 ASSERT_TRUE(child.good()); | 756 ASSERT_TRUE(child.good()); |
| 759 child.Put(syncable::IS_UNSYNCED, true); | 757 child.Put(syncable::IS_UNSYNCED, true); |
| 760 child.Put(syncable::IS_DIR, true); | 758 child.Put(syncable::IS_DIR, true); |
| 761 child.Put(syncable::ID, ids_.FromNumber(105)); | 759 child.Put(syncable::ID, ids_.FromNumber(105)); |
| 762 child.Put(syncable::BASE_VERSION, 1); | 760 child.Put(syncable::BASE_VERSION, 1); |
| 763 } | 761 } |
| 764 | 762 |
| 765 syncer_->SyncShare(session_.get()); | 763 syncer_->SyncShare(session_.get()); |
| 766 EXPECT_TRUE(6 == session_->status_controller()->unsynced_handles().size()); | 764 EXPECT_TRUE(6 == session_->status_controller()->unsynced_handles().size()); |
| 767 ASSERT_TRUE(6 == mock_server_->committed_ids().size()); | 765 ASSERT_TRUE(6 == mock_server_->committed_ids().size()); |
| 768 // If this test starts failing, be aware other sort orders could be valid. | 766 // If this test starts failing, be aware other sort orders could be valid. |
| 769 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); | 767 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); |
| 770 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); | 768 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); |
| 771 EXPECT_TRUE(ids_.FromNumber(102) == mock_server_->committed_ids()[2]); | 769 EXPECT_TRUE(ids_.FromNumber(102) == mock_server_->committed_ids()[2]); |
| 772 EXPECT_TRUE(ids_.FromNumber(-103) == mock_server_->committed_ids()[3]); | 770 EXPECT_TRUE(ids_.FromNumber(-103) == mock_server_->committed_ids()[3]); |
| 773 EXPECT_TRUE(ids_.FromNumber(-104) == mock_server_->committed_ids()[4]); | 771 EXPECT_TRUE(ids_.FromNumber(-104) == mock_server_->committed_ids()[4]); |
| 774 EXPECT_TRUE(ids_.FromNumber(105) == mock_server_->committed_ids()[5]); | 772 EXPECT_TRUE(ids_.FromNumber(105) == mock_server_->committed_ids()[5]); |
| 775 } | 773 } |
| 776 | 774 |
| 777 TEST_F(SyncerTest, TestCommitListOrderingCounterexample) { | 775 TEST_F(SyncerTest, TestCommitListOrderingCounterexample) { |
| 778 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 776 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 779 ASSERT_TRUE(dir.good()); | 777 ASSERT_TRUE(dir.good()); |
| 780 | 778 |
| 781 syncable::Id child2_id = ids_.NewServerId(); | 779 syncable::Id child2_id = ids_.NewServerId(); |
| 782 | 780 |
| 783 { | 781 { |
| 784 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 782 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 785 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), PSTR("P")); | 783 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "P"); |
| 786 ASSERT_TRUE(parent.good()); | 784 ASSERT_TRUE(parent.good()); |
| 787 parent.Put(syncable::IS_UNSYNCED, true); | 785 parent.Put(syncable::IS_UNSYNCED, true); |
| 788 parent.Put(syncable::IS_DIR, true); | 786 parent.Put(syncable::IS_DIR, true); |
| 789 parent.Put(syncable::ID, parent_id_); | 787 parent.Put(syncable::ID, parent_id_); |
| 790 MutableEntry child1(&wtrans, syncable::CREATE, parent_id_, PSTR("1")); | 788 MutableEntry child1(&wtrans, syncable::CREATE, parent_id_, "1"); |
| 791 ASSERT_TRUE(child1.good()); | 789 ASSERT_TRUE(child1.good()); |
| 792 child1.Put(syncable::IS_UNSYNCED, true); | 790 child1.Put(syncable::IS_UNSYNCED, true); |
| 793 child1.Put(syncable::ID, child_id_); | 791 child1.Put(syncable::ID, child_id_); |
| 794 MutableEntry child2(&wtrans, syncable::CREATE, parent_id_, PSTR("2")); | 792 MutableEntry child2(&wtrans, syncable::CREATE, parent_id_, "2"); |
| 795 ASSERT_TRUE(child2.good()); | 793 ASSERT_TRUE(child2.good()); |
| 796 child2.Put(syncable::IS_UNSYNCED, true); | 794 child2.Put(syncable::IS_UNSYNCED, true); |
| 797 child2.Put(syncable::ID, child2_id); | 795 child2.Put(syncable::ID, child2_id); |
| 798 parent.Put(syncable::BASE_VERSION, 1); | 796 parent.Put(syncable::BASE_VERSION, 1); |
| 799 child1.Put(syncable::BASE_VERSION, 1); | 797 child1.Put(syncable::BASE_VERSION, 1); |
| 800 child2.Put(syncable::BASE_VERSION, 1); | 798 child2.Put(syncable::BASE_VERSION, 1); |
| 801 } | 799 } |
| 802 | 800 |
| 803 syncer_->SyncShare(session_.get()); | 801 syncer_->SyncShare(session_.get()); |
| 804 EXPECT_TRUE(3 == session_->status_controller()->unsynced_handles().size()); | 802 EXPECT_TRUE(3 == session_->status_controller()->unsynced_handles().size()); |
| 805 ASSERT_TRUE(3 == mock_server_->committed_ids().size()); | 803 ASSERT_TRUE(3 == mock_server_->committed_ids().size()); |
| 806 // If this test starts failing, be aware other sort orders could be valid. | 804 // If this test starts failing, be aware other sort orders could be valid. |
| 807 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); | 805 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); |
| 808 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); | 806 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); |
| 809 EXPECT_TRUE(child2_id == mock_server_->committed_ids()[2]); | 807 EXPECT_TRUE(child2_id == mock_server_->committed_ids()[2]); |
| 810 } | 808 } |
| 811 | 809 |
| 812 TEST_F(SyncerTest, TestCommitListOrderingAndNewParent) { | 810 TEST_F(SyncerTest, TestCommitListOrderingAndNewParent) { |
| 813 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 811 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 814 ASSERT_TRUE(dir.good()); | 812 ASSERT_TRUE(dir.good()); |
| 815 | 813 |
| 816 PathString parent1_name = PSTR("1"); | 814 string parent1_name = "1"; |
| 817 PathString parent2_name = PSTR("A"); | 815 string parent2_name = "A"; |
| 818 PathString child_name = PSTR("B"); | 816 string child_name = "B"; |
| 819 | 817 |
| 820 { | 818 { |
| 821 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 819 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 822 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), parent1_nam
e); | 820 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), parent1_nam
e); |
| 823 ASSERT_TRUE(parent.good()); | 821 ASSERT_TRUE(parent.good()); |
| 824 parent.Put(syncable::IS_UNSYNCED, true); | 822 parent.Put(syncable::IS_UNSYNCED, true); |
| 825 parent.Put(syncable::IS_DIR, true); | 823 parent.Put(syncable::IS_DIR, true); |
| 826 parent.Put(syncable::ID, parent_id_); | 824 parent.Put(syncable::ID, parent_id_); |
| 827 parent.Put(syncable::BASE_VERSION, 1); | 825 parent.Put(syncable::BASE_VERSION, 1); |
| 828 } | 826 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 | 871 |
| 874 Entry child(&rtrans, syncable::GET_BY_ID, child_id); | 872 Entry child(&rtrans, syncable::GET_BY_ID, child_id); |
| 875 EXPECT_EQ(parent2_committed_id, child.Get(syncable::PARENT_ID)); | 873 EXPECT_EQ(parent2_committed_id, child.Get(syncable::PARENT_ID)); |
| 876 } | 874 } |
| 877 } | 875 } |
| 878 | 876 |
| 879 TEST_F(SyncerTest, TestCommitListOrderingAndNewParentAndChild) { | 877 TEST_F(SyncerTest, TestCommitListOrderingAndNewParentAndChild) { |
| 880 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 878 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 881 ASSERT_TRUE(dir.good()); | 879 ASSERT_TRUE(dir.good()); |
| 882 | 880 |
| 883 PathString parent_name = PSTR("1"); | 881 string parent_name = "1"; |
| 884 PathString parent2_name = PSTR("A"); | 882 string parent2_name = "A"; |
| 885 PathString child_name = PSTR("B"); | 883 string child_name = "B"; |
| 886 | 884 |
| 887 { | 885 { |
| 888 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 886 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 889 MutableEntry parent(&wtrans, | 887 MutableEntry parent(&wtrans, |
| 890 syncable::CREATE, | 888 syncable::CREATE, |
| 891 wtrans.root_id(), | 889 wtrans.root_id(), |
| 892 parent_name); | 890 parent_name); |
| 893 ASSERT_TRUE(parent.good()); | 891 ASSERT_TRUE(parent.good()); |
| 894 parent.Put(syncable::IS_UNSYNCED, true); | 892 parent.Put(syncable::IS_UNSYNCED, true); |
| 895 parent.Put(syncable::IS_DIR, true); | 893 parent.Put(syncable::IS_DIR, true); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 mock_server_->AddUpdateDirectory(2, 0, "foo:", 1, 20); | 971 mock_server_->AddUpdateDirectory(2, 0, "foo:", 1, 20); |
| 974 SyncRepeatedlyToTriggerStuckSignal(session_.get()); | 972 SyncRepeatedlyToTriggerStuckSignal(session_.get()); |
| 975 EXPECT_FALSE(session_->status_controller()->syncer_status().syncer_stuck); | 973 EXPECT_FALSE(session_->status_controller()->syncer_status().syncer_stuck); |
| 976 syncer_events_.clear(); | 974 syncer_events_.clear(); |
| 977 } | 975 } |
| 978 | 976 |
| 979 TEST_F(SyncerTest, ExtendedAttributeWithNullCharacter) { | 977 TEST_F(SyncerTest, ExtendedAttributeWithNullCharacter) { |
| 980 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 978 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 981 ASSERT_TRUE(dir.good()); | 979 ASSERT_TRUE(dir.good()); |
| 982 size_t xattr_count = 2; | 980 size_t xattr_count = 2; |
| 983 PathString xattr_keys[] = { PSTR("key"), PSTR("key2") }; | 981 string xattr_keys[] = { "key", "key2" }; |
| 984 syncable::Blob xattr_values[2]; | 982 syncable::Blob xattr_values[2]; |
| 985 const char* value[] = { "value", "val\0ue" }; | 983 const char* value[] = { "value", "val\0ue" }; |
| 986 int value_length[] = { 5, 6 }; | 984 int value_length[] = { 5, 6 }; |
| 987 for (size_t i = 0; i < xattr_count; i++) { | 985 for (size_t i = 0; i < xattr_count; i++) { |
| 988 for (int j = 0; j < value_length[i]; j++) | 986 for (int j = 0; j < value_length[i]; j++) |
| 989 xattr_values[i].push_back(value[i][j]); | 987 xattr_values[i].push_back(value[i][j]); |
| 990 } | 988 } |
| 991 sync_pb::SyncEntity* ent = | 989 sync_pb::SyncEntity* ent = |
| 992 mock_server_->AddUpdateBookmark(1, 0, "bob", 1, 10); | 990 mock_server_->AddUpdateBookmark(1, 0, "bob", 1, 10); |
| 993 mock_server_->AddUpdateExtendedAttributes( | 991 mock_server_->AddUpdateExtendedAttributes( |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1125 Entry still_a_dir(&trans, GET_BY_ID, ids_.FromNumber(10)); | 1123 Entry still_a_dir(&trans, GET_BY_ID, ids_.FromNumber(10)); |
| 1126 ASSERT_TRUE(still_a_dir.good()); | 1124 ASSERT_TRUE(still_a_dir.good()); |
| 1127 EXPECT_FALSE(still_a_dir.Get(IS_UNAPPLIED_UPDATE)); | 1125 EXPECT_FALSE(still_a_dir.Get(IS_UNAPPLIED_UPDATE)); |
| 1128 EXPECT_TRUE(10 == still_a_dir.Get(BASE_VERSION)); | 1126 EXPECT_TRUE(10 == still_a_dir.Get(BASE_VERSION)); |
| 1129 EXPECT_TRUE(10 == still_a_dir.Get(SERVER_VERSION)); | 1127 EXPECT_TRUE(10 == still_a_dir.Get(SERVER_VERSION)); |
| 1130 EXPECT_TRUE(still_a_dir.Get(IS_DIR)); | 1128 EXPECT_TRUE(still_a_dir.Get(IS_DIR)); |
| 1131 | 1129 |
| 1132 Entry rename(&trans, GET_BY_ID, ids_.FromNumber(1)); | 1130 Entry rename(&trans, GET_BY_ID, ids_.FromNumber(1)); |
| 1133 ASSERT_TRUE(rename.good()); | 1131 ASSERT_TRUE(rename.good()); |
| 1134 EXPECT_EQ(root, rename.Get(PARENT_ID)); | 1132 EXPECT_EQ(root, rename.Get(PARENT_ID)); |
| 1135 EXPECT_EQ(PSTR("new_name"), rename.Get(NON_UNIQUE_NAME)); | 1133 EXPECT_EQ("new_name", rename.Get(NON_UNIQUE_NAME)); |
| 1136 EXPECT_FALSE(rename.Get(IS_UNAPPLIED_UPDATE)); | 1134 EXPECT_FALSE(rename.Get(IS_UNAPPLIED_UPDATE)); |
| 1137 EXPECT_TRUE(ids_.FromNumber(1) == rename.Get(ID)); | 1135 EXPECT_TRUE(ids_.FromNumber(1) == rename.Get(ID)); |
| 1138 EXPECT_TRUE(20 == rename.Get(BASE_VERSION)); | 1136 EXPECT_TRUE(20 == rename.Get(BASE_VERSION)); |
| 1139 | 1137 |
| 1140 Entry name_clash(&trans, GET_BY_ID, ids_.FromNumber(2)); | 1138 Entry name_clash(&trans, GET_BY_ID, ids_.FromNumber(2)); |
| 1141 ASSERT_TRUE(name_clash.good()); | 1139 ASSERT_TRUE(name_clash.good()); |
| 1142 EXPECT_EQ(root, name_clash.Get(PARENT_ID)); | 1140 EXPECT_EQ(root, name_clash.Get(PARENT_ID)); |
| 1143 EXPECT_TRUE(ids_.FromNumber(2) == name_clash.Get(ID)); | 1141 EXPECT_TRUE(ids_.FromNumber(2) == name_clash.Get(ID)); |
| 1144 EXPECT_TRUE(10 == name_clash.Get(BASE_VERSION)); | 1142 EXPECT_TRUE(10 == name_clash.Get(BASE_VERSION)); |
| 1145 EXPECT_EQ(PSTR("in_root"), name_clash.Get(NON_UNIQUE_NAME)); | 1143 EXPECT_EQ("in_root", name_clash.Get(NON_UNIQUE_NAME)); |
| 1146 | 1144 |
| 1147 Entry ignored_old_version(&trans, GET_BY_ID, ids_.FromNumber(4)); | 1145 Entry ignored_old_version(&trans, GET_BY_ID, ids_.FromNumber(4)); |
| 1148 ASSERT_TRUE(ignored_old_version.good()); | 1146 ASSERT_TRUE(ignored_old_version.good()); |
| 1149 EXPECT_TRUE( | 1147 EXPECT_TRUE( |
| 1150 ignored_old_version.Get(NON_UNIQUE_NAME) == PSTR("newer_version")); | 1148 ignored_old_version.Get(NON_UNIQUE_NAME) == "newer_version"); |
| 1151 EXPECT_FALSE(ignored_old_version.Get(IS_UNAPPLIED_UPDATE)); | 1149 EXPECT_FALSE(ignored_old_version.Get(IS_UNAPPLIED_UPDATE)); |
| 1152 EXPECT_TRUE(20 == ignored_old_version.Get(BASE_VERSION)); | 1150 EXPECT_TRUE(20 == ignored_old_version.Get(BASE_VERSION)); |
| 1153 | 1151 |
| 1154 Entry circular_parent_issue(&trans, GET_BY_ID, ids_.FromNumber(5)); | 1152 Entry circular_parent_issue(&trans, GET_BY_ID, ids_.FromNumber(5)); |
| 1155 ASSERT_TRUE(circular_parent_issue.good()); | 1153 ASSERT_TRUE(circular_parent_issue.good()); |
| 1156 EXPECT_TRUE(circular_parent_issue.Get(IS_UNAPPLIED_UPDATE)) | 1154 EXPECT_TRUE(circular_parent_issue.Get(IS_UNAPPLIED_UPDATE)) |
| 1157 << "circular move should be in conflict"; | 1155 << "circular move should be in conflict"; |
| 1158 EXPECT_TRUE(circular_parent_issue.Get(PARENT_ID) == root_id_); | 1156 EXPECT_TRUE(circular_parent_issue.Get(PARENT_ID) == root_id_); |
| 1159 EXPECT_TRUE(circular_parent_issue.Get(SERVER_PARENT_ID) == | 1157 EXPECT_TRUE(circular_parent_issue.Get(SERVER_PARENT_ID) == |
| 1160 ids_.FromNumber(6)); | 1158 ids_.FromNumber(6)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1174 | 1172 |
| 1175 TEST_F(SyncerTest, CommitTimeRename) { | 1173 TEST_F(SyncerTest, CommitTimeRename) { |
| 1176 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1174 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1177 ASSERT_TRUE(dir.good()); | 1175 ASSERT_TRUE(dir.good()); |
| 1178 int64 metahandle_folder; | 1176 int64 metahandle_folder; |
| 1179 int64 metahandle_new_entry; | 1177 int64 metahandle_new_entry; |
| 1180 | 1178 |
| 1181 // Create a folder and an entry. | 1179 // Create a folder and an entry. |
| 1182 { | 1180 { |
| 1183 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 1181 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 1184 MutableEntry parent(&trans, CREATE, root_id_, PSTR("Folder")); | 1182 MutableEntry parent(&trans, CREATE, root_id_, "Folder"); |
| 1185 ASSERT_TRUE(parent.good()); | 1183 ASSERT_TRUE(parent.good()); |
| 1186 parent.Put(IS_DIR, true); | 1184 parent.Put(IS_DIR, true); |
| 1187 parent.Put(IS_UNSYNCED, true); | 1185 parent.Put(IS_UNSYNCED, true); |
| 1188 metahandle_folder = parent.Get(META_HANDLE); | 1186 metahandle_folder = parent.Get(META_HANDLE); |
| 1189 | 1187 |
| 1190 MutableEntry entry(&trans, CREATE, parent.Get(ID), PSTR("new_entry")); | 1188 MutableEntry entry(&trans, CREATE, parent.Get(ID), "new_entry"); |
| 1191 ASSERT_TRUE(entry.good()); | 1189 ASSERT_TRUE(entry.good()); |
| 1192 metahandle_new_entry = entry.Get(META_HANDLE); | 1190 metahandle_new_entry = entry.Get(META_HANDLE); |
| 1193 WriteTestDataToEntry(&trans, &entry); | 1191 WriteTestDataToEntry(&trans, &entry); |
| 1194 } | 1192 } |
| 1195 | 1193 |
| 1196 // Mix in a directory creation too for later. | 1194 // Mix in a directory creation too for later. |
| 1197 mock_server_->AddUpdateDirectory(2, 0, "dir_in_root", 10, 10); | 1195 mock_server_->AddUpdateDirectory(2, 0, "dir_in_root", 10, 10); |
| 1198 mock_server_->SetCommitTimeRename("renamed_"); | 1196 mock_server_->SetCommitTimeRename("renamed_"); |
| 1199 syncer_->SyncShare(this); | 1197 syncer_->SyncShare(this); |
| 1200 | 1198 |
| 1201 // Verify it was correctly renamed. | 1199 // Verify it was correctly renamed. |
| 1202 { | 1200 { |
| 1203 ReadTransaction trans(dir, __FILE__, __LINE__); | 1201 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 1204 Entry entry_folder(&trans, GET_BY_HANDLE, metahandle_folder); | 1202 Entry entry_folder(&trans, GET_BY_HANDLE, metahandle_folder); |
| 1205 ASSERT_TRUE(entry_folder.good()); | 1203 ASSERT_TRUE(entry_folder.good()); |
| 1206 EXPECT_EQ(PSTR("renamed_Folder"), entry_folder.Get(NON_UNIQUE_NAME)); | 1204 EXPECT_EQ("renamed_Folder", entry_folder.Get(NON_UNIQUE_NAME)); |
| 1207 | 1205 |
| 1208 Entry entry_new(&trans, GET_BY_HANDLE, metahandle_new_entry); | 1206 Entry entry_new(&trans, GET_BY_HANDLE, metahandle_new_entry); |
| 1209 ASSERT_TRUE(entry_new.good()); | 1207 ASSERT_TRUE(entry_new.good()); |
| 1210 EXPECT_EQ(entry_folder.Get(ID), entry_new.Get(PARENT_ID)); | 1208 EXPECT_EQ(entry_folder.Get(ID), entry_new.Get(PARENT_ID)); |
| 1211 EXPECT_EQ(PSTR("renamed_new_entry"), entry_new.Get(NON_UNIQUE_NAME)); | 1209 EXPECT_EQ("renamed_new_entry", entry_new.Get(NON_UNIQUE_NAME)); |
| 1212 | 1210 |
| 1213 // And that the unrelated directory creation worked without a rename. | 1211 // And that the unrelated directory creation worked without a rename. |
| 1214 Entry new_dir(&trans, GET_BY_ID, ids_.FromNumber(2)); | 1212 Entry new_dir(&trans, GET_BY_ID, ids_.FromNumber(2)); |
| 1215 EXPECT_TRUE(new_dir.good()); | 1213 EXPECT_TRUE(new_dir.good()); |
| 1216 EXPECT_EQ(PSTR("dir_in_root"), new_dir.Get(NON_UNIQUE_NAME)); | 1214 EXPECT_EQ("dir_in_root", new_dir.Get(NON_UNIQUE_NAME)); |
| 1217 } | 1215 } |
| 1218 } | 1216 } |
| 1219 | 1217 |
| 1220 | 1218 |
| 1221 TEST_F(SyncerTest, CommitTimeRenameI18N) { | 1219 TEST_F(SyncerTest, CommitTimeRenameI18N) { |
| 1222 // This is utf-8 for the diacritized Internationalization. | 1220 // This is utf-8 for the diacritized Internationalization. |
| 1223 const char* i18nString = "\xc3\x8e\xc3\xb1\x74\xc3\xa9\x72\xc3\xb1" | 1221 const char* i18nString = "\xc3\x8e\xc3\xb1\x74\xc3\xa9\x72\xc3\xb1" |
| 1224 "\xc3\xa5\x74\xc3\xae\xc3\xb6\xc3\xb1\xc3\xa5\x6c\xc3\xae" | 1222 "\xc3\xa5\x74\xc3\xae\xc3\xb6\xc3\xb1\xc3\xa5\x6c\xc3\xae" |
| 1225 "\xc2\x9e\xc3\xa5\x74\xc3\xae\xc3\xb6\xc3\xb1"; | 1223 "\xc2\x9e\xc3\xa5\x74\xc3\xae\xc3\xb6\xc3\xb1"; |
| 1226 | 1224 |
| 1227 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1225 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1228 ASSERT_TRUE(dir.good()); | 1226 ASSERT_TRUE(dir.good()); |
| 1229 int64 metahandle; | 1227 int64 metahandle; |
| 1230 // Create a folder, expect a commit time rename. | 1228 // Create a folder, expect a commit time rename. |
| 1231 { | 1229 { |
| 1232 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 1230 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 1233 MutableEntry parent(&trans, CREATE, root_id_, PSTR("Folder")); | 1231 MutableEntry parent(&trans, CREATE, root_id_, "Folder"); |
| 1234 ASSERT_TRUE(parent.good()); | 1232 ASSERT_TRUE(parent.good()); |
| 1235 parent.Put(IS_DIR, true); | 1233 parent.Put(IS_DIR, true); |
| 1236 parent.Put(IS_UNSYNCED, true); | 1234 parent.Put(IS_UNSYNCED, true); |
| 1237 metahandle = parent.Get(META_HANDLE); | 1235 metahandle = parent.Get(META_HANDLE); |
| 1238 } | 1236 } |
| 1239 | 1237 |
| 1240 mock_server_->SetCommitTimeRename(i18nString); | 1238 mock_server_->SetCommitTimeRename(i18nString); |
| 1241 syncer_->SyncShare(this); | 1239 syncer_->SyncShare(this); |
| 1242 | 1240 |
| 1243 // Verify it was correctly renamed. | 1241 // Verify it was correctly renamed. |
| 1244 { | 1242 { |
| 1245 ReadTransaction trans(dir, __FILE__, __LINE__); | 1243 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 1246 PathString expected_folder_name(i18nString); | 1244 string expected_folder_name(i18nString); |
| 1247 expected_folder_name.append("Folder"); | 1245 expected_folder_name.append("Folder"); |
| 1248 | 1246 |
| 1249 | 1247 |
| 1250 Entry entry_folder(&trans, GET_BY_HANDLE, metahandle); | 1248 Entry entry_folder(&trans, GET_BY_HANDLE, metahandle); |
| 1251 ASSERT_TRUE(entry_folder.good()); | 1249 ASSERT_TRUE(entry_folder.good()); |
| 1252 EXPECT_EQ(expected_folder_name, entry_folder.Get(NON_UNIQUE_NAME)); | 1250 EXPECT_EQ(expected_folder_name, entry_folder.Get(NON_UNIQUE_NAME)); |
| 1253 } | 1251 } |
| 1254 } | 1252 } |
| 1255 | 1253 |
| 1256 // A commit with a lost response produces an update that has to be reunited with | 1254 // A commit with a lost response produces an update that has to be reunited with |
| 1257 // its parent. | 1255 // its parent. |
| 1258 TEST_F(SyncerTest, CommitReuniteUpdateAdjustsChildren) { | 1256 TEST_F(SyncerTest, CommitReuniteUpdateAdjustsChildren) { |
| 1259 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1257 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1260 ASSERT_TRUE(dir.good()); | 1258 ASSERT_TRUE(dir.good()); |
| 1261 | 1259 |
| 1262 // Create a folder in the root. | 1260 // Create a folder in the root. |
| 1263 int64 metahandle_folder; | 1261 int64 metahandle_folder; |
| 1264 { | 1262 { |
| 1265 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 1263 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 1266 MutableEntry entry(&trans, CREATE, trans.root_id(), PSTR("new_folder")); | 1264 MutableEntry entry(&trans, CREATE, trans.root_id(), "new_folder"); |
| 1267 ASSERT_TRUE(entry.good()); | 1265 ASSERT_TRUE(entry.good()); |
| 1268 entry.Put(IS_DIR, true); | 1266 entry.Put(IS_DIR, true); |
| 1269 entry.Put(IS_UNSYNCED, true); | 1267 entry.Put(IS_UNSYNCED, true); |
| 1270 metahandle_folder = entry.Get(META_HANDLE); | 1268 metahandle_folder = entry.Get(META_HANDLE); |
| 1271 } | 1269 } |
| 1272 | 1270 |
| 1273 // Verify it and pull the ID out of the folder. | 1271 // Verify it and pull the ID out of the folder. |
| 1274 syncable::Id folder_id; | 1272 syncable::Id folder_id; |
| 1275 int64 metahandle_entry; | 1273 int64 metahandle_entry; |
| 1276 { | 1274 { |
| 1277 ReadTransaction trans(dir, __FILE__, __LINE__); | 1275 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 1278 Entry entry(&trans, GET_BY_HANDLE, metahandle_folder); | 1276 Entry entry(&trans, GET_BY_HANDLE, metahandle_folder); |
| 1279 ASSERT_TRUE(entry.good()); | 1277 ASSERT_TRUE(entry.good()); |
| 1280 folder_id = entry.Get(ID); | 1278 folder_id = entry.Get(ID); |
| 1281 ASSERT_TRUE(!folder_id.ServerKnows()); | 1279 ASSERT_TRUE(!folder_id.ServerKnows()); |
| 1282 } | 1280 } |
| 1283 | 1281 |
| 1284 // Create an entry in the newly created folder. | 1282 // Create an entry in the newly created folder. |
| 1285 { | 1283 { |
| 1286 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 1284 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 1287 MutableEntry entry(&trans, CREATE, folder_id, PSTR("new_entry")); | 1285 MutableEntry entry(&trans, CREATE, folder_id, "new_entry"); |
| 1288 ASSERT_TRUE(entry.good()); | 1286 ASSERT_TRUE(entry.good()); |
| 1289 metahandle_entry = entry.Get(META_HANDLE); | 1287 metahandle_entry = entry.Get(META_HANDLE); |
| 1290 WriteTestDataToEntry(&trans, &entry); | 1288 WriteTestDataToEntry(&trans, &entry); |
| 1291 } | 1289 } |
| 1292 | 1290 |
| 1293 // Verify it and pull the ID out of the entry. | 1291 // Verify it and pull the ID out of the entry. |
| 1294 syncable::Id entry_id; | 1292 syncable::Id entry_id; |
| 1295 { | 1293 { |
| 1296 ReadTransaction trans(dir, __FILE__, __LINE__); | 1294 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 1297 Entry entry(&trans, syncable::GET_BY_HANDLE, metahandle_entry); | 1295 Entry entry(&trans, syncable::GET_BY_HANDLE, metahandle_entry); |
| 1298 ASSERT_TRUE(entry.good()); | 1296 ASSERT_TRUE(entry.good()); |
| 1299 EXPECT_EQ(folder_id, entry.Get(PARENT_ID)); | 1297 EXPECT_EQ(folder_id, entry.Get(PARENT_ID)); |
| 1300 EXPECT_EQ(PSTR("new_entry"), entry.Get(NON_UNIQUE_NAME)); | 1298 EXPECT_EQ("new_entry", entry.Get(NON_UNIQUE_NAME)); |
| 1301 entry_id = entry.Get(ID); | 1299 entry_id = entry.Get(ID); |
| 1302 EXPECT_TRUE(!entry_id.ServerKnows()); | 1300 EXPECT_TRUE(!entry_id.ServerKnows()); |
| 1303 VerifyTestDataInEntry(&trans, &entry); | 1301 VerifyTestDataInEntry(&trans, &entry); |
| 1304 } | 1302 } |
| 1305 | 1303 |
| 1306 // Now, to emulate a commit response failure, we just don't commit it. | 1304 // Now, to emulate a commit response failure, we just don't commit it. |
| 1307 int64 new_version = 150; // any larger value. | 1305 int64 new_version = 150; // any larger value. |
| 1308 int64 timestamp = 20; // arbitrary value. | 1306 int64 timestamp = 20; // arbitrary value. |
| 1309 syncable::Id new_folder_id = | 1307 syncable::Id new_folder_id = |
| 1310 syncable::Id::CreateFromServerId("folder_server_id"); | 1308 syncable::Id::CreateFromServerId("folder_server_id"); |
| 1311 | 1309 |
| 1312 // The following update should cause the folder to both apply the update, as | 1310 // The following update should cause the folder to both apply the update, as |
| 1313 // well as reassociate the id. | 1311 // well as reassociate the id. |
| 1314 mock_server_->AddUpdateDirectory(new_folder_id, root_id_, | 1312 mock_server_->AddUpdateDirectory(new_folder_id, root_id_, |
| 1315 "new_folder", new_version, timestamp); | 1313 "new_folder", new_version, timestamp); |
| 1316 mock_server_->SetLastUpdateOriginatorFields( | 1314 mock_server_->SetLastUpdateOriginatorFields( |
| 1317 dir->cache_guid(), folder_id.GetServerId()); | 1315 dir->cache_guid(), folder_id.GetServerId()); |
| 1318 | 1316 |
| 1319 // We don't want it accidentally committed, just the update applied. | 1317 // We don't want it accidentally committed, just the update applied. |
| 1320 mock_server_->set_conflict_all_commits(true); | 1318 mock_server_->set_conflict_all_commits(true); |
| 1321 | 1319 |
| 1322 // Alright! Apply that update! | 1320 // Alright! Apply that update! |
| 1323 syncer_->SyncShare(this); | 1321 syncer_->SyncShare(this); |
| 1324 { | 1322 { |
| 1325 // The folder's ID should have been updated. | 1323 // The folder's ID should have been updated. |
| 1326 ReadTransaction trans(dir, __FILE__, __LINE__); | 1324 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 1327 Entry folder(&trans, GET_BY_HANDLE, metahandle_folder); | 1325 Entry folder(&trans, GET_BY_HANDLE, metahandle_folder); |
| 1328 ASSERT_TRUE(folder.good()); | 1326 ASSERT_TRUE(folder.good()); |
| 1329 EXPECT_EQ(PSTR("new_folder"), folder.Get(NON_UNIQUE_NAME)); | 1327 EXPECT_EQ("new_folder", folder.Get(NON_UNIQUE_NAME)); |
| 1330 EXPECT_TRUE(new_version == folder.Get(BASE_VERSION)); | 1328 EXPECT_TRUE(new_version == folder.Get(BASE_VERSION)); |
| 1331 EXPECT_TRUE(new_folder_id == folder.Get(ID)); | 1329 EXPECT_TRUE(new_folder_id == folder.Get(ID)); |
| 1332 EXPECT_TRUE(folder.Get(ID).ServerKnows()); | 1330 EXPECT_TRUE(folder.Get(ID).ServerKnows()); |
| 1333 EXPECT_EQ(trans.root_id(), folder.Get(PARENT_ID)); | 1331 EXPECT_EQ(trans.root_id(), folder.Get(PARENT_ID)); |
| 1334 | 1332 |
| 1335 // Since it was updated, the old folder should not exist. | 1333 // Since it was updated, the old folder should not exist. |
| 1336 Entry old_dead_folder(&trans, GET_BY_ID, folder_id); | 1334 Entry old_dead_folder(&trans, GET_BY_ID, folder_id); |
| 1337 EXPECT_FALSE(old_dead_folder.good()); | 1335 EXPECT_FALSE(old_dead_folder.good()); |
| 1338 | 1336 |
| 1339 // The child's parent should have changed. | 1337 // The child's parent should have changed. |
| 1340 Entry entry(&trans, syncable::GET_BY_HANDLE, metahandle_entry); | 1338 Entry entry(&trans, syncable::GET_BY_HANDLE, metahandle_entry); |
| 1341 ASSERT_TRUE(entry.good()); | 1339 ASSERT_TRUE(entry.good()); |
| 1342 EXPECT_EQ(PSTR("new_entry"), entry.Get(NON_UNIQUE_NAME)); | 1340 EXPECT_EQ("new_entry", entry.Get(NON_UNIQUE_NAME)); |
| 1343 EXPECT_EQ(new_folder_id, entry.Get(PARENT_ID)); | 1341 EXPECT_EQ(new_folder_id, entry.Get(PARENT_ID)); |
| 1344 EXPECT_TRUE(!entry.Get(ID).ServerKnows()); | 1342 EXPECT_TRUE(!entry.Get(ID).ServerKnows()); |
| 1345 VerifyTestDataInEntry(&trans, &entry); | 1343 VerifyTestDataInEntry(&trans, &entry); |
| 1346 } | 1344 } |
| 1347 } | 1345 } |
| 1348 | 1346 |
| 1349 // A commit with a lost response produces an update that has to be reunited with | 1347 // A commit with a lost response produces an update that has to be reunited with |
| 1350 // its parent. | 1348 // its parent. |
| 1351 TEST_F(SyncerTest, CommitReuniteUpdate) { | 1349 TEST_F(SyncerTest, CommitReuniteUpdate) { |
| 1352 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1350 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1353 ASSERT_TRUE(dir.good()); | 1351 ASSERT_TRUE(dir.good()); |
| 1354 | 1352 |
| 1355 // Create an entry in the root. | 1353 // Create an entry in the root. |
| 1356 int64 entry_metahandle; | 1354 int64 entry_metahandle; |
| 1357 { | 1355 { |
| 1358 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 1356 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 1359 MutableEntry entry(&trans, CREATE, trans.root_id(), PSTR("new_entry")); | 1357 MutableEntry entry(&trans, CREATE, trans.root_id(), "new_entry"); |
| 1360 ASSERT_TRUE(entry.good()); | 1358 ASSERT_TRUE(entry.good()); |
| 1361 entry_metahandle = entry.Get(META_HANDLE); | 1359 entry_metahandle = entry.Get(META_HANDLE); |
| 1362 WriteTestDataToEntry(&trans, &entry); | 1360 WriteTestDataToEntry(&trans, &entry); |
| 1363 } | 1361 } |
| 1364 | 1362 |
| 1365 // Verify it and pull the ID out. | 1363 // Verify it and pull the ID out. |
| 1366 syncable::Id entry_id; | 1364 syncable::Id entry_id; |
| 1367 { | 1365 { |
| 1368 ReadTransaction trans(dir, __FILE__, __LINE__); | 1366 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 1369 | 1367 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1389 mock_server_->set_conflict_all_commits(true); | 1387 mock_server_->set_conflict_all_commits(true); |
| 1390 | 1388 |
| 1391 // Alright! Apply that update! | 1389 // Alright! Apply that update! |
| 1392 syncer_->SyncShare(this); | 1390 syncer_->SyncShare(this); |
| 1393 { | 1391 { |
| 1394 ReadTransaction trans(dir, __FILE__, __LINE__); | 1392 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 1395 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle); | 1393 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle); |
| 1396 ASSERT_TRUE(entry.good()); | 1394 ASSERT_TRUE(entry.good()); |
| 1397 EXPECT_TRUE(new_version == entry.Get(BASE_VERSION)); | 1395 EXPECT_TRUE(new_version == entry.Get(BASE_VERSION)); |
| 1398 EXPECT_TRUE(new_entry_id == entry.Get(ID)); | 1396 EXPECT_TRUE(new_entry_id == entry.Get(ID)); |
| 1399 EXPECT_EQ(PSTR("new_entry"), entry.Get(NON_UNIQUE_NAME)); | 1397 EXPECT_EQ("new_entry", entry.Get(NON_UNIQUE_NAME)); |
| 1400 } | 1398 } |
| 1401 } | 1399 } |
| 1402 | 1400 |
| 1403 // A commit with a lost response must work even if the local entry was deleted | 1401 // A commit with a lost response must work even if the local entry was deleted |
| 1404 // before the update is applied. We should not duplicate the local entry in | 1402 // before the update is applied. We should not duplicate the local entry in |
| 1405 // this case, but just create another one alongside. We may wish to examine | 1403 // this case, but just create another one alongside. We may wish to examine |
| 1406 // this behavior in the future as it can create hanging uploads that never | 1404 // this behavior in the future as it can create hanging uploads that never |
| 1407 // finish, that must be cleaned up on the server side after some time. | 1405 // finish, that must be cleaned up on the server side after some time. |
| 1408 TEST_F(SyncerTest, CommitReuniteUpdateDoesNotChokeOnDeletedLocalEntry) { | 1406 TEST_F(SyncerTest, CommitReuniteUpdateDoesNotChokeOnDeletedLocalEntry) { |
| 1409 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1407 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1410 ASSERT_TRUE(dir.good()); | 1408 ASSERT_TRUE(dir.good()); |
| 1411 | 1409 |
| 1412 // Create a entry in the root. | 1410 // Create a entry in the root. |
| 1413 int64 entry_metahandle; | 1411 int64 entry_metahandle; |
| 1414 { | 1412 { |
| 1415 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 1413 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 1416 MutableEntry entry(&trans, CREATE, trans.root_id(), PSTR("new_entry")); | 1414 MutableEntry entry(&trans, CREATE, trans.root_id(), "new_entry"); |
| 1417 ASSERT_TRUE(entry.good()); | 1415 ASSERT_TRUE(entry.good()); |
| 1418 entry_metahandle = entry.Get(META_HANDLE); | 1416 entry_metahandle = entry.Get(META_HANDLE); |
| 1419 WriteTestDataToEntry(&trans, &entry); | 1417 WriteTestDataToEntry(&trans, &entry); |
| 1420 } | 1418 } |
| 1421 // Verify it and pull the ID out. | 1419 // Verify it and pull the ID out. |
| 1422 syncable::Id entry_id; | 1420 syncable::Id entry_id; |
| 1423 { | 1421 { |
| 1424 ReadTransaction trans(dir, __FILE__, __LINE__); | 1422 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 1425 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle); | 1423 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle); |
| 1426 ASSERT_TRUE(entry.good()); | 1424 ASSERT_TRUE(entry.good()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1441 dir->cache_guid(), | 1439 dir->cache_guid(), |
| 1442 entry_id.GetServerId()); | 1440 entry_id.GetServerId()); |
| 1443 | 1441 |
| 1444 // We don't want it accidentally committed, just the update applied. | 1442 // We don't want it accidentally committed, just the update applied. |
| 1445 mock_server_->set_conflict_all_commits(true); | 1443 mock_server_->set_conflict_all_commits(true); |
| 1446 | 1444 |
| 1447 // Purposefully delete the entry now before the update application finishes. | 1445 // Purposefully delete the entry now before the update application finishes. |
| 1448 { | 1446 { |
| 1449 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 1447 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 1450 Id new_entry_id = GetOnlyEntryWithName( | 1448 Id new_entry_id = GetOnlyEntryWithName( |
| 1451 &trans, trans.root_id(), PSTR("new_entry")); | 1449 &trans, trans.root_id(), "new_entry"); |
| 1452 MutableEntry entry(&trans, GET_BY_ID, new_entry_id); | 1450 MutableEntry entry(&trans, GET_BY_ID, new_entry_id); |
| 1453 ASSERT_TRUE(entry.good()); | 1451 ASSERT_TRUE(entry.good()); |
| 1454 entry.Put(syncable::IS_DEL, true); | 1452 entry.Put(syncable::IS_DEL, true); |
| 1455 } | 1453 } |
| 1456 | 1454 |
| 1457 // Just don't CHECK fail in sync, have the update split. | 1455 // Just don't CHECK fail in sync, have the update split. |
| 1458 syncer_->SyncShare(this); | 1456 syncer_->SyncShare(this); |
| 1459 { | 1457 { |
| 1460 ReadTransaction trans(dir, __FILE__, __LINE__); | 1458 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 1461 Id new_entry_id = GetOnlyEntryWithName( | 1459 Id new_entry_id = GetOnlyEntryWithName( |
| 1462 &trans, trans.root_id(), PSTR("new_entry")); | 1460 &trans, trans.root_id(), "new_entry"); |
| 1463 Entry entry(&trans, GET_BY_ID, new_entry_id); | 1461 Entry entry(&trans, GET_BY_ID, new_entry_id); |
| 1464 ASSERT_TRUE(entry.good()); | 1462 ASSERT_TRUE(entry.good()); |
| 1465 EXPECT_FALSE(entry.Get(IS_DEL)); | 1463 EXPECT_FALSE(entry.Get(IS_DEL)); |
| 1466 | 1464 |
| 1467 Entry old_entry(&trans, GET_BY_ID, entry_id); | 1465 Entry old_entry(&trans, GET_BY_ID, entry_id); |
| 1468 ASSERT_TRUE(old_entry.good()); | 1466 ASSERT_TRUE(old_entry.good()); |
| 1469 EXPECT_TRUE(old_entry.Get(IS_DEL)); | 1467 EXPECT_TRUE(old_entry.Get(IS_DEL)); |
| 1470 } | 1468 } |
| 1471 } | 1469 } |
| 1472 | 1470 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1560 ASSERT_TRUE(dir.good()); | 1558 ASSERT_TRUE(dir.good()); |
| 1561 mock_server_->AddUpdateDirectory(4, 3, "ggchild", 10, 10); | 1559 mock_server_->AddUpdateDirectory(4, 3, "ggchild", 10, 10); |
| 1562 mock_server_->AddUpdateDirectory(3, 2, "gchild", 10, 10); | 1560 mock_server_->AddUpdateDirectory(3, 2, "gchild", 10, 10); |
| 1563 mock_server_->AddUpdateDirectory(5, 4, "gggchild", 10, 10); | 1561 mock_server_->AddUpdateDirectory(5, 4, "gggchild", 10, 10); |
| 1564 mock_server_->AddUpdateDirectory(2, 1, "child", 10, 10); | 1562 mock_server_->AddUpdateDirectory(2, 1, "child", 10, 10); |
| 1565 mock_server_->AddUpdateDirectory(1, 0, "parent", 10, 10); | 1563 mock_server_->AddUpdateDirectory(1, 0, "parent", 10, 10); |
| 1566 LoopSyncShare(syncer_); | 1564 LoopSyncShare(syncer_); |
| 1567 ReadTransaction trans(dir, __FILE__, __LINE__); | 1565 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 1568 | 1566 |
| 1569 Id child_id = GetOnlyEntryWithName( | 1567 Id child_id = GetOnlyEntryWithName( |
| 1570 &trans, ids_.FromNumber(4), PSTR("gggchild")); | 1568 &trans, ids_.FromNumber(4), "gggchild"); |
| 1571 Entry child(&trans, GET_BY_ID, child_id); | 1569 Entry child(&trans, GET_BY_ID, child_id); |
| 1572 ASSERT_TRUE(child.good()); | 1570 ASSERT_TRUE(child.good()); |
| 1573 } | 1571 } |
| 1574 | 1572 |
| 1575 class EntryCreatedInNewFolderTest : public SyncerTest { | 1573 class EntryCreatedInNewFolderTest : public SyncerTest { |
| 1576 public: | 1574 public: |
| 1577 void CreateFolderInBob() { | 1575 void CreateFolderInBob() { |
| 1578 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1576 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1579 CHECK(dir.good()); | 1577 CHECK(dir.good()); |
| 1580 | 1578 |
| 1581 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 1579 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 1582 MutableEntry bob(&trans, | 1580 MutableEntry bob(&trans, |
| 1583 syncable::GET_BY_ID, | 1581 syncable::GET_BY_ID, |
| 1584 GetOnlyEntryWithName(&trans, | 1582 GetOnlyEntryWithName(&trans, |
| 1585 TestIdFactory::root(), | 1583 TestIdFactory::root(), |
| 1586 PSTR("bob"))); | 1584 "bob")); |
| 1587 CHECK(bob.good()); | 1585 CHECK(bob.good()); |
| 1588 | 1586 |
| 1589 MutableEntry entry2(&trans, syncable::CREATE, bob.Get(syncable::ID), | 1587 MutableEntry entry2(&trans, syncable::CREATE, bob.Get(syncable::ID), |
| 1590 PSTR("bob")); | 1588 "bob"); |
| 1591 CHECK(entry2.good()); | 1589 CHECK(entry2.good()); |
| 1592 entry2.Put(syncable::IS_DIR, true); | 1590 entry2.Put(syncable::IS_DIR, true); |
| 1593 entry2.Put(syncable::IS_UNSYNCED, true); | 1591 entry2.Put(syncable::IS_UNSYNCED, true); |
| 1594 } | 1592 } |
| 1595 }; | 1593 }; |
| 1596 | 1594 |
| 1597 TEST_F(EntryCreatedInNewFolderTest, EntryCreatedInNewFolderMidSync) { | 1595 TEST_F(EntryCreatedInNewFolderTest, EntryCreatedInNewFolderMidSync) { |
| 1598 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1596 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1599 CHECK(dir.good()); | 1597 CHECK(dir.good()); |
| 1600 { | 1598 { |
| 1601 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 1599 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 1602 MutableEntry entry(&trans, syncable::CREATE, trans.root_id(), | 1600 MutableEntry entry(&trans, syncable::CREATE, trans.root_id(), |
| 1603 PSTR("bob")); | 1601 "bob"); |
| 1604 ASSERT_TRUE(entry.good()); | 1602 ASSERT_TRUE(entry.good()); |
| 1605 entry.Put(syncable::IS_DIR, true); | 1603 entry.Put(syncable::IS_DIR, true); |
| 1606 entry.Put(syncable::IS_UNSYNCED, true); | 1604 entry.Put(syncable::IS_UNSYNCED, true); |
| 1607 } | 1605 } |
| 1608 | 1606 |
| 1609 mock_server_->SetMidCommitCallback( | 1607 mock_server_->SetMidCommitCallback( |
| 1610 NewCallback<EntryCreatedInNewFolderTest>(this, | 1608 NewCallback<EntryCreatedInNewFolderTest>(this, |
| 1611 &EntryCreatedInNewFolderTest::CreateFolderInBob)); | 1609 &EntryCreatedInNewFolderTest::CreateFolderInBob)); |
| 1612 syncer_->SyncShare(BUILD_COMMIT_REQUEST, SYNCER_END, this); | 1610 syncer_->SyncShare(BUILD_COMMIT_REQUEST, SYNCER_END, this); |
| 1613 EXPECT_TRUE(1 == mock_server_->committed_ids().size()); | 1611 EXPECT_TRUE(1 == mock_server_->committed_ids().size()); |
| 1614 { | 1612 { |
| 1615 ReadTransaction trans(dir, __FILE__, __LINE__); | 1613 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 1616 Entry parent_entry(&trans, syncable::GET_BY_ID, | 1614 Entry parent_entry(&trans, syncable::GET_BY_ID, |
| 1617 GetOnlyEntryWithName(&trans, TestIdFactory::root(), PSTR("bob"))); | 1615 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob")); |
| 1618 ASSERT_TRUE(parent_entry.good()); | 1616 ASSERT_TRUE(parent_entry.good()); |
| 1619 | 1617 |
| 1620 Id child_id = | 1618 Id child_id = |
| 1621 GetOnlyEntryWithName(&trans, parent_entry.Get(ID), PSTR("bob")); | 1619 GetOnlyEntryWithName(&trans, parent_entry.Get(ID), "bob"); |
| 1622 Entry child(&trans, syncable::GET_BY_ID, child_id); | 1620 Entry child(&trans, syncable::GET_BY_ID, child_id); |
| 1623 ASSERT_TRUE(child.good()); | 1621 ASSERT_TRUE(child.good()); |
| 1624 EXPECT_EQ(parent_entry.Get(ID), child.Get(PARENT_ID)); | 1622 EXPECT_EQ(parent_entry.Get(ID), child.Get(PARENT_ID)); |
| 1625 } | 1623 } |
| 1626 } | 1624 } |
| 1627 | 1625 |
| 1628 TEST_F(SyncerTest, NegativeIDInUpdate) { | 1626 TEST_F(SyncerTest, NegativeIDInUpdate) { |
| 1629 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1627 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1630 CHECK(dir.good()); | 1628 CHECK(dir.good()); |
| 1631 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40); | 1629 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40); |
| 1632 syncer_->SyncShare(this); | 1630 syncer_->SyncShare(this); |
| 1633 // The negative id would make us CHECK! | 1631 // The negative id would make us CHECK! |
| 1634 } | 1632 } |
| 1635 | 1633 |
| 1636 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) { | 1634 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) { |
| 1637 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1635 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1638 CHECK(dir.good()); | 1636 CHECK(dir.good()); |
| 1639 | 1637 |
| 1640 int64 metahandle_fred; | 1638 int64 metahandle_fred; |
| 1641 { | 1639 { |
| 1642 // Create an item. | 1640 // Create an item. |
| 1643 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 1641 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 1644 MutableEntry fred_match(&trans, CREATE, trans.root_id(), | 1642 MutableEntry fred_match(&trans, CREATE, trans.root_id(), |
| 1645 PSTR("fred_match")); | 1643 "fred_match"); |
| 1646 ASSERT_TRUE(fred_match.good()); | 1644 ASSERT_TRUE(fred_match.good()); |
| 1647 metahandle_fred = fred_match.Get(META_HANDLE); | 1645 metahandle_fred = fred_match.Get(META_HANDLE); |
| 1648 WriteTestDataToEntry(&trans, &fred_match); | 1646 WriteTestDataToEntry(&trans, &fred_match); |
| 1649 } | 1647 } |
| 1650 // Commit it. | 1648 // Commit it. |
| 1651 syncer_->SyncShare(this); | 1649 syncer_->SyncShare(this); |
| 1652 EXPECT_TRUE(1 == mock_server_->committed_ids().size()); | 1650 EXPECT_TRUE(1 == mock_server_->committed_ids().size()); |
| 1653 mock_server_->set_conflict_all_commits(true); | 1651 mock_server_->set_conflict_all_commits(true); |
| 1654 syncable::Id fred_match_id; | 1652 syncable::Id fred_match_id; |
| 1655 { | 1653 { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1672 * In the event that we have a double changed entry, that is changed on both | 1670 * In the event that we have a double changed entry, that is changed on both |
| 1673 * the client and the server, the conflict resolver should just drop one of | 1671 * the client and the server, the conflict resolver should just drop one of |
| 1674 * them and accept the other. | 1672 * them and accept the other. |
| 1675 */ | 1673 */ |
| 1676 | 1674 |
| 1677 TEST_F(SyncerTest, DoublyChangedWithResolver) { | 1675 TEST_F(SyncerTest, DoublyChangedWithResolver) { |
| 1678 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1676 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1679 CHECK(dir.good()); | 1677 CHECK(dir.good()); |
| 1680 { | 1678 { |
| 1681 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 1679 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 1682 MutableEntry parent(&wtrans, syncable::CREATE, root_id_, PSTR("Folder")); | 1680 MutableEntry parent(&wtrans, syncable::CREATE, root_id_, "Folder"); |
| 1683 ASSERT_TRUE(parent.good()); | 1681 ASSERT_TRUE(parent.good()); |
| 1684 parent.Put(syncable::IS_DIR, true); | 1682 parent.Put(syncable::IS_DIR, true); |
| 1685 parent.Put(syncable::ID, parent_id_); | 1683 parent.Put(syncable::ID, parent_id_); |
| 1686 parent.Put(syncable::BASE_VERSION, 5); | 1684 parent.Put(syncable::BASE_VERSION, 5); |
| 1687 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, PSTR("Pete.htm")); | 1685 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete.htm"); |
| 1688 ASSERT_TRUE(child.good()); | 1686 ASSERT_TRUE(child.good()); |
| 1689 child.Put(syncable::ID, child_id_); | 1687 child.Put(syncable::ID, child_id_); |
| 1690 child.Put(syncable::BASE_VERSION, 10); | 1688 child.Put(syncable::BASE_VERSION, 10); |
| 1691 WriteTestDataToEntry(&wtrans, &child); | 1689 WriteTestDataToEntry(&wtrans, &child); |
| 1692 } | 1690 } |
| 1693 mock_server_->AddUpdateBookmark(child_id_, parent_id_, "Pete.htm", 11, 10); | 1691 mock_server_->AddUpdateBookmark(child_id_, parent_id_, "Pete.htm", 11, 10); |
| 1694 mock_server_->set_conflict_all_commits(true); | 1692 mock_server_->set_conflict_all_commits(true); |
| 1695 LoopSyncShare(syncer_); | 1693 LoopSyncShare(syncer_); |
| 1696 syncable::Directory::ChildHandles children; | 1694 syncable::Directory::ChildHandles children; |
| 1697 { | 1695 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1711 | 1709 |
| 1712 // We got this repro case when someone was editing bookmarks while sync was | 1710 // We got this repro case when someone was editing bookmarks while sync was |
| 1713 // occuring. The entry had changed out underneath the user. | 1711 // occuring. The entry had changed out underneath the user. |
| 1714 TEST_F(SyncerTest, CommitsUpdateDoesntAlterEntry) { | 1712 TEST_F(SyncerTest, CommitsUpdateDoesntAlterEntry) { |
| 1715 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1713 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1716 CHECK(dir.good()); | 1714 CHECK(dir.good()); |
| 1717 int64 test_time = 123456; | 1715 int64 test_time = 123456; |
| 1718 int64 entry_metahandle; | 1716 int64 entry_metahandle; |
| 1719 { | 1717 { |
| 1720 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 1718 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 1721 MutableEntry entry(&wtrans, syncable::CREATE, root_id_, PSTR("Pete")); | 1719 MutableEntry entry(&wtrans, syncable::CREATE, root_id_, "Pete"); |
| 1722 ASSERT_TRUE(entry.good()); | 1720 ASSERT_TRUE(entry.good()); |
| 1723 EXPECT_FALSE(entry.Get(ID).ServerKnows()); | 1721 EXPECT_FALSE(entry.Get(ID).ServerKnows()); |
| 1724 entry.Put(syncable::IS_DIR, true); | 1722 entry.Put(syncable::IS_DIR, true); |
| 1725 entry.Put(syncable::IS_UNSYNCED, true); | 1723 entry.Put(syncable::IS_UNSYNCED, true); |
| 1726 entry.Put(syncable::MTIME, test_time); | 1724 entry.Put(syncable::MTIME, test_time); |
| 1727 entry_metahandle = entry.Get(META_HANDLE); | 1725 entry_metahandle = entry.Get(META_HANDLE); |
| 1728 } | 1726 } |
| 1729 syncer_->SyncShare(this); | 1727 syncer_->SyncShare(this); |
| 1730 syncable::Id id; | 1728 syncable::Id id; |
| 1731 int64 version; | 1729 int64 version; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1751 } | 1749 } |
| 1752 | 1750 |
| 1753 TEST_F(SyncerTest, ParentAndChildBothMatch) { | 1751 TEST_F(SyncerTest, ParentAndChildBothMatch) { |
| 1754 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1752 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1755 CHECK(dir.good()); | 1753 CHECK(dir.good()); |
| 1756 syncable::Id parent_id = ids_.NewServerId(); | 1754 syncable::Id parent_id = ids_.NewServerId(); |
| 1757 syncable::Id child_id = ids_.NewServerId(); | 1755 syncable::Id child_id = ids_.NewServerId(); |
| 1758 | 1756 |
| 1759 { | 1757 { |
| 1760 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 1758 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 1761 MutableEntry parent(&wtrans, CREATE, root_id_, PSTR("Folder")); | 1759 MutableEntry parent(&wtrans, CREATE, root_id_, "Folder"); |
| 1762 ASSERT_TRUE(parent.good()); | 1760 ASSERT_TRUE(parent.good()); |
| 1763 parent.Put(IS_DIR, true); | 1761 parent.Put(IS_DIR, true); |
| 1764 parent.Put(IS_UNSYNCED, true); | 1762 parent.Put(IS_UNSYNCED, true); |
| 1765 parent.Put(ID, parent_id); | 1763 parent.Put(ID, parent_id); |
| 1766 parent.Put(BASE_VERSION, 1); | 1764 parent.Put(BASE_VERSION, 1); |
| 1767 parent.Put(IS_BOOKMARK_OBJECT, true); | 1765 parent.Put(IS_BOOKMARK_OBJECT, true); |
| 1768 | 1766 |
| 1769 MutableEntry child(&wtrans, CREATE, parent.Get(ID), PSTR("test.htm")); | 1767 MutableEntry child(&wtrans, CREATE, parent.Get(ID), "test.htm"); |
| 1770 ASSERT_TRUE(child.good()); | 1768 ASSERT_TRUE(child.good()); |
| 1771 child.Put(ID, child_id); | 1769 child.Put(ID, child_id); |
| 1772 child.Put(BASE_VERSION, 1); | 1770 child.Put(BASE_VERSION, 1); |
| 1773 child.Put(IS_BOOKMARK_OBJECT, true); | 1771 child.Put(IS_BOOKMARK_OBJECT, true); |
| 1774 WriteTestDataToEntry(&wtrans, &child); | 1772 WriteTestDataToEntry(&wtrans, &child); |
| 1775 } | 1773 } |
| 1776 mock_server_->AddUpdateDirectory(parent_id, root_id_, "Folder", 10, 10); | 1774 mock_server_->AddUpdateDirectory(parent_id, root_id_, "Folder", 10, 10); |
| 1777 mock_server_->AddUpdateBookmark(child_id, parent_id, "test.htm", 10, 10); | 1775 mock_server_->AddUpdateBookmark(child_id, parent_id, "test.htm", 10, 10); |
| 1778 mock_server_->set_conflict_all_commits(true); | 1776 mock_server_->set_conflict_all_commits(true); |
| 1779 syncer_->SyncShare(this); | 1777 syncer_->SyncShare(this); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1794 EXPECT_TRUE(0 == unsynced.size()); | 1792 EXPECT_TRUE(0 == unsynced.size()); |
| 1795 syncer_events_.clear(); | 1793 syncer_events_.clear(); |
| 1796 } | 1794 } |
| 1797 } | 1795 } |
| 1798 | 1796 |
| 1799 TEST_F(SyncerTest, CommittingNewDeleted) { | 1797 TEST_F(SyncerTest, CommittingNewDeleted) { |
| 1800 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1798 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1801 CHECK(dir.good()); | 1799 CHECK(dir.good()); |
| 1802 { | 1800 { |
| 1803 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 1801 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 1804 MutableEntry entry(&trans, CREATE, trans.root_id(), PSTR("bob")); | 1802 MutableEntry entry(&trans, CREATE, trans.root_id(), "bob"); |
| 1805 entry.Put(IS_UNSYNCED, true); | 1803 entry.Put(IS_UNSYNCED, true); |
| 1806 entry.Put(IS_DEL, true); | 1804 entry.Put(IS_DEL, true); |
| 1807 } | 1805 } |
| 1808 syncer_->SyncShare(this); | 1806 syncer_->SyncShare(this); |
| 1809 EXPECT_TRUE(0 == mock_server_->committed_ids().size()); | 1807 EXPECT_TRUE(0 == mock_server_->committed_ids().size()); |
| 1810 } | 1808 } |
| 1811 | 1809 |
| 1812 // Original problem synopsis: | 1810 // Original problem synopsis: |
| 1813 // Check failed: entry->Get(BASE_VERSION) <= entry->Get(SERVER_VERSION) | 1811 // Check failed: entry->Get(BASE_VERSION) <= entry->Get(SERVER_VERSION) |
| 1814 // Client creates entry, client finishes committing entry. Between | 1812 // Client creates entry, client finishes committing entry. Between |
| 1815 // commit and getting update back, we delete the entry. | 1813 // commit and getting update back, we delete the entry. |
| 1816 // We get the update for the entry, but the local one was modified | 1814 // We get the update for the entry, but the local one was modified |
| 1817 // so we store the entry but don't apply it. IS_UNAPPLIED_UPDATE is set. | 1815 // so we store the entry but don't apply it. IS_UNAPPLIED_UPDATE is set. |
| 1818 // We commit deletion and get a new version number. | 1816 // We commit deletion and get a new version number. |
| 1819 // We apply unapplied updates again before we get the update about the deletion. | 1817 // We apply unapplied updates again before we get the update about the deletion. |
| 1820 // This means we have an unapplied update where server_version < base_version. | 1818 // This means we have an unapplied update where server_version < base_version. |
| 1821 TEST_F(SyncerTest, UnappliedUpdateDuringCommit) { | 1819 TEST_F(SyncerTest, UnappliedUpdateDuringCommit) { |
| 1822 // This test is a little fake. | 1820 // This test is a little fake. |
| 1823 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1821 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1824 CHECK(dir.good()); | 1822 CHECK(dir.good()); |
| 1825 { | 1823 { |
| 1826 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 1824 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 1827 MutableEntry entry(&trans, CREATE, trans.root_id(), PSTR("bob")); | 1825 MutableEntry entry(&trans, CREATE, trans.root_id(), "bob"); |
| 1828 entry.Put(ID, ids_.FromNumber(20)); | 1826 entry.Put(ID, ids_.FromNumber(20)); |
| 1829 entry.Put(BASE_VERSION, 1); | 1827 entry.Put(BASE_VERSION, 1); |
| 1830 entry.Put(SERVER_VERSION, 1); | 1828 entry.Put(SERVER_VERSION, 1); |
| 1831 entry.Put(SERVER_PARENT_ID, ids_.FromNumber(9999)); // Bad parent. | 1829 entry.Put(SERVER_PARENT_ID, ids_.FromNumber(9999)); // Bad parent. |
| 1832 entry.Put(IS_UNSYNCED, true); | 1830 entry.Put(IS_UNSYNCED, true); |
| 1833 entry.Put(IS_UNAPPLIED_UPDATE, true); | 1831 entry.Put(IS_UNAPPLIED_UPDATE, true); |
| 1834 entry.Put(IS_DEL, false); | 1832 entry.Put(IS_DEL, false); |
| 1835 } | 1833 } |
| 1836 syncer_->SyncShare(session_.get()); | 1834 syncer_->SyncShare(session_.get()); |
| 1837 syncer_->SyncShare(session_.get()); | 1835 syncer_->SyncShare(session_.get()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1852 // remove fred | 1850 // remove fred |
| 1853 // if no syncing occured midway, bob will have an illegal parent | 1851 // if no syncing occured midway, bob will have an illegal parent |
| 1854 TEST_F(SyncerTest, DeletingEntryInFolder) { | 1852 TEST_F(SyncerTest, DeletingEntryInFolder) { |
| 1855 // This test is a little fake. | 1853 // This test is a little fake. |
| 1856 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1854 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1857 CHECK(dir.good()); | 1855 CHECK(dir.good()); |
| 1858 | 1856 |
| 1859 int64 existing_metahandle; | 1857 int64 existing_metahandle; |
| 1860 { | 1858 { |
| 1861 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 1859 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 1862 MutableEntry entry(&trans, CREATE, trans.root_id(), PSTR("existing")); | 1860 MutableEntry entry(&trans, CREATE, trans.root_id(), "existing"); |
| 1863 ASSERT_TRUE(entry.good()); | 1861 ASSERT_TRUE(entry.good()); |
| 1864 entry.Put(IS_DIR, true); | 1862 entry.Put(IS_DIR, true); |
| 1865 entry.Put(IS_UNSYNCED, true); | 1863 entry.Put(IS_UNSYNCED, true); |
| 1866 existing_metahandle = entry.Get(META_HANDLE); | 1864 existing_metahandle = entry.Get(META_HANDLE); |
| 1867 } | 1865 } |
| 1868 syncer_->SyncShare(session_.get()); | 1866 syncer_->SyncShare(session_.get()); |
| 1869 { | 1867 { |
| 1870 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 1868 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 1871 MutableEntry newfolder(&trans, CREATE, trans.root_id(), PSTR("new")); | 1869 MutableEntry newfolder(&trans, CREATE, trans.root_id(), "new"); |
| 1872 ASSERT_TRUE(newfolder.good()); | 1870 ASSERT_TRUE(newfolder.good()); |
| 1873 newfolder.Put(IS_DIR, true); | 1871 newfolder.Put(IS_DIR, true); |
| 1874 newfolder.Put(IS_UNSYNCED, true); | 1872 newfolder.Put(IS_UNSYNCED, true); |
| 1875 | 1873 |
| 1876 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle); | 1874 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle); |
| 1877 ASSERT_TRUE(existing.good()); | 1875 ASSERT_TRUE(existing.good()); |
| 1878 existing.Put(PARENT_ID, newfolder.Get(ID)); | 1876 existing.Put(PARENT_ID, newfolder.Get(ID)); |
| 1879 existing.Put(IS_UNSYNCED, true); | 1877 existing.Put(IS_UNSYNCED, true); |
| 1880 EXPECT_TRUE(existing.Get(ID).ServerKnows()); | 1878 EXPECT_TRUE(existing.Get(ID).ServerKnows()); |
| 1881 | 1879 |
| 1882 newfolder.Put(IS_DEL, true); | 1880 newfolder.Put(IS_DEL, true); |
| 1883 existing.Put(IS_DEL, true); | 1881 existing.Put(IS_DEL, true); |
| 1884 } | 1882 } |
| 1885 syncer_->SyncShare(session_.get()); | 1883 syncer_->SyncShare(session_.get()); |
| 1886 StatusController* status(session_->status_controller()); | 1884 StatusController* status(session_->status_controller()); |
| 1887 EXPECT_TRUE(0 == status->error_counters().num_conflicting_commits); | 1885 EXPECT_TRUE(0 == status->error_counters().num_conflicting_commits); |
| 1888 } | 1886 } |
| 1889 | 1887 |
| 1890 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) { | 1888 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) { |
| 1891 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1889 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1892 CHECK(dir.good()); | 1890 CHECK(dir.good()); |
| 1893 int64 newfolder_metahandle; | 1891 int64 newfolder_metahandle; |
| 1894 | 1892 |
| 1895 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); | 1893 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); |
| 1896 syncer_->SyncShare(this); | 1894 syncer_->SyncShare(this); |
| 1897 { | 1895 { |
| 1898 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 1896 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 1899 MutableEntry newfolder(&trans, CREATE, ids_.FromNumber(1), PSTR("local")); | 1897 MutableEntry newfolder(&trans, CREATE, ids_.FromNumber(1), "local"); |
| 1900 ASSERT_TRUE(newfolder.good()); | 1898 ASSERT_TRUE(newfolder.good()); |
| 1901 newfolder.Put(IS_UNSYNCED, true); | 1899 newfolder.Put(IS_UNSYNCED, true); |
| 1902 newfolder_metahandle = newfolder.Get(META_HANDLE); | 1900 newfolder_metahandle = newfolder.Get(META_HANDLE); |
| 1903 } | 1901 } |
| 1904 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20); | 1902 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20); |
| 1905 mock_server_->SetLastUpdateDeleted(); | 1903 mock_server_->SetLastUpdateDeleted(); |
| 1906 syncer_->SyncShare(SYNCER_BEGIN, APPLY_UPDATES, this); | 1904 syncer_->SyncShare(SYNCER_BEGIN, APPLY_UPDATES, this); |
| 1907 { | 1905 { |
| 1908 ReadTransaction trans(dir, __FILE__, __LINE__); | 1906 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 1909 Entry entry(&trans, syncable::GET_BY_HANDLE, newfolder_metahandle); | 1907 Entry entry(&trans, syncable::GET_BY_HANDLE, newfolder_metahandle); |
| 1910 ASSERT_TRUE(entry.good()); | 1908 ASSERT_TRUE(entry.good()); |
| 1911 } | 1909 } |
| 1912 } | 1910 } |
| 1913 | 1911 |
| 1914 TEST_F(SyncerTest, FolderSwapUpdate) { | 1912 TEST_F(SyncerTest, FolderSwapUpdate) { |
| 1915 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1913 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1916 CHECK(dir.good()); | 1914 CHECK(dir.good()); |
| 1917 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10); | 1915 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10); |
| 1918 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10); | 1916 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10); |
| 1919 syncer_->SyncShare(this); | 1917 syncer_->SyncShare(this); |
| 1920 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20); | 1918 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20); |
| 1921 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20); | 1919 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20); |
| 1922 syncer_->SyncShare(this); | 1920 syncer_->SyncShare(this); |
| 1923 { | 1921 { |
| 1924 ReadTransaction trans(dir, __FILE__, __LINE__); | 1922 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 1925 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); | 1923 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); |
| 1926 ASSERT_TRUE(id1.good()); | 1924 ASSERT_TRUE(id1.good()); |
| 1927 EXPECT_TRUE(PSTR("fred") == id1.Get(NON_UNIQUE_NAME)); | 1925 EXPECT_TRUE("fred" == id1.Get(NON_UNIQUE_NAME)); |
| 1928 EXPECT_TRUE(root_id_ == id1.Get(PARENT_ID)); | 1926 EXPECT_TRUE(root_id_ == id1.Get(PARENT_ID)); |
| 1929 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); | 1927 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); |
| 1930 ASSERT_TRUE(id2.good()); | 1928 ASSERT_TRUE(id2.good()); |
| 1931 EXPECT_TRUE(PSTR("bob") == id2.Get(NON_UNIQUE_NAME)); | 1929 EXPECT_TRUE("bob" == id2.Get(NON_UNIQUE_NAME)); |
| 1932 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID)); | 1930 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID)); |
| 1933 } | 1931 } |
| 1934 syncer_events_.clear(); | 1932 syncer_events_.clear(); |
| 1935 } | 1933 } |
| 1936 | 1934 |
| 1937 TEST_F(SyncerTest, NameCollidingFolderSwapWorksFine) { | 1935 TEST_F(SyncerTest, NameCollidingFolderSwapWorksFine) { |
| 1938 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1936 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1939 CHECK(dir.good()); | 1937 CHECK(dir.good()); |
| 1940 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10); | 1938 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10); |
| 1941 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10); | 1939 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10); |
| 1942 mock_server_->AddUpdateDirectory(4096, 0, "alice", 1, 10); | 1940 mock_server_->AddUpdateDirectory(4096, 0, "alice", 1, 10); |
| 1943 syncer_->SyncShare(this); | 1941 syncer_->SyncShare(this); |
| 1944 { | 1942 { |
| 1945 ReadTransaction trans(dir, __FILE__, __LINE__); | 1943 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 1946 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); | 1944 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); |
| 1947 ASSERT_TRUE(id1.good()); | 1945 ASSERT_TRUE(id1.good()); |
| 1948 EXPECT_TRUE(PSTR("bob") == id1.Get(NON_UNIQUE_NAME)); | 1946 EXPECT_TRUE("bob" == id1.Get(NON_UNIQUE_NAME)); |
| 1949 EXPECT_TRUE(root_id_ == id1.Get(PARENT_ID)); | 1947 EXPECT_TRUE(root_id_ == id1.Get(PARENT_ID)); |
| 1950 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); | 1948 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); |
| 1951 ASSERT_TRUE(id2.good()); | 1949 ASSERT_TRUE(id2.good()); |
| 1952 EXPECT_TRUE(PSTR("fred") == id2.Get(NON_UNIQUE_NAME)); | 1950 EXPECT_TRUE("fred" == id2.Get(NON_UNIQUE_NAME)); |
| 1953 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID)); | 1951 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID)); |
| 1954 Entry id3(&trans, GET_BY_ID, ids_.FromNumber(4096)); | 1952 Entry id3(&trans, GET_BY_ID, ids_.FromNumber(4096)); |
| 1955 ASSERT_TRUE(id3.good()); | 1953 ASSERT_TRUE(id3.good()); |
| 1956 EXPECT_TRUE(PSTR("alice") == id3.Get(NON_UNIQUE_NAME)); | 1954 EXPECT_TRUE("alice" == id3.Get(NON_UNIQUE_NAME)); |
| 1957 EXPECT_TRUE(root_id_ == id3.Get(PARENT_ID)); | 1955 EXPECT_TRUE(root_id_ == id3.Get(PARENT_ID)); |
| 1958 } | 1956 } |
| 1959 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20); | 1957 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20); |
| 1960 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20); | 1958 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20); |
| 1961 mock_server_->AddUpdateDirectory(4096, 0, "bob", 2, 20); | 1959 mock_server_->AddUpdateDirectory(4096, 0, "bob", 2, 20); |
| 1962 syncer_->SyncShare(this); | 1960 syncer_->SyncShare(this); |
| 1963 { | 1961 { |
| 1964 ReadTransaction trans(dir, __FILE__, __LINE__); | 1962 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 1965 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); | 1963 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); |
| 1966 ASSERT_TRUE(id1.good()); | 1964 ASSERT_TRUE(id1.good()); |
| 1967 EXPECT_TRUE(PSTR("fred") == id1.Get(NON_UNIQUE_NAME)); | 1965 EXPECT_TRUE("fred" == id1.Get(NON_UNIQUE_NAME)); |
| 1968 EXPECT_TRUE(root_id_ == id1.Get(PARENT_ID)); | 1966 EXPECT_TRUE(root_id_ == id1.Get(PARENT_ID)); |
| 1969 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); | 1967 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); |
| 1970 ASSERT_TRUE(id2.good()); | 1968 ASSERT_TRUE(id2.good()); |
| 1971 EXPECT_TRUE(PSTR("bob") == id2.Get(NON_UNIQUE_NAME)); | 1969 EXPECT_TRUE("bob" == id2.Get(NON_UNIQUE_NAME)); |
| 1972 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID)); | 1970 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID)); |
| 1973 Entry id3(&trans, GET_BY_ID, ids_.FromNumber(4096)); | 1971 Entry id3(&trans, GET_BY_ID, ids_.FromNumber(4096)); |
| 1974 ASSERT_TRUE(id3.good()); | 1972 ASSERT_TRUE(id3.good()); |
| 1975 EXPECT_TRUE(PSTR("bob") == id3.Get(NON_UNIQUE_NAME)); | 1973 EXPECT_TRUE("bob" == id3.Get(NON_UNIQUE_NAME)); |
| 1976 EXPECT_TRUE(root_id_ == id3.Get(PARENT_ID)); | 1974 EXPECT_TRUE(root_id_ == id3.Get(PARENT_ID)); |
| 1977 } | 1975 } |
| 1978 syncer_events_.clear(); | 1976 syncer_events_.clear(); |
| 1979 } | 1977 } |
| 1980 | 1978 |
| 1981 TEST_F(SyncerTest, CommitManyItemsInOneGo) { | 1979 TEST_F(SyncerTest, CommitManyItemsInOneGo) { |
| 1982 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1980 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1983 uint32 max_batches = 3; | 1981 uint32 max_batches = 3; |
| 1984 uint32 items_to_commit = kDefaultMaxCommitBatchSize * max_batches; | 1982 uint32 items_to_commit = kDefaultMaxCommitBatchSize * max_batches; |
| 1985 CHECK(dir.good()); | 1983 CHECK(dir.good()); |
| 1986 { | 1984 { |
| 1987 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 1985 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 1988 for (uint32 i = 0; i < items_to_commit; i++) { | 1986 for (uint32 i = 0; i < items_to_commit; i++) { |
| 1989 string nameutf8 = StringPrintf("%d", i); | 1987 string nameutf8 = StringPrintf("%d", i); |
| 1990 PathString name(nameutf8.begin(), nameutf8.end()); | 1988 string name(nameutf8.begin(), nameutf8.end()); |
| 1991 MutableEntry e(&trans, CREATE, trans.root_id(), name); | 1989 MutableEntry e(&trans, CREATE, trans.root_id(), name); |
| 1992 e.Put(IS_UNSYNCED, true); | 1990 e.Put(IS_UNSYNCED, true); |
| 1993 e.Put(IS_DIR, true); | 1991 e.Put(IS_DIR, true); |
| 1994 } | 1992 } |
| 1995 } | 1993 } |
| 1996 uint32 num_loops = 0; | 1994 uint32 num_loops = 0; |
| 1997 while (syncer_->SyncShare(this)) { | 1995 while (syncer_->SyncShare(this)) { |
| 1998 num_loops++; | 1996 num_loops++; |
| 1999 ASSERT_LT(num_loops, max_batches * 2); | 1997 ASSERT_LT(num_loops, max_batches * 2); |
| 2000 } | 1998 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2082 | 2080 |
| 2083 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath) { | 2081 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath) { |
| 2084 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 2082 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 2085 CHECK(dir.good()); | 2083 CHECK(dir.good()); |
| 2086 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10); | 2084 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10); |
| 2087 syncer_->SyncShare(this); | 2085 syncer_->SyncShare(this); |
| 2088 int64 local_folder_handle; | 2086 int64 local_folder_handle; |
| 2089 syncable::Id local_folder_id; | 2087 syncable::Id local_folder_id; |
| 2090 { | 2088 { |
| 2091 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 2089 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 2092 MutableEntry new_entry(&wtrans, CREATE, wtrans.root_id(), PSTR("Bar.htm")); | 2090 MutableEntry new_entry(&wtrans, CREATE, wtrans.root_id(), "Bar.htm"); |
| 2093 ASSERT_TRUE(new_entry.good()); | 2091 ASSERT_TRUE(new_entry.good()); |
| 2094 local_folder_id = new_entry.Get(ID); | 2092 local_folder_id = new_entry.Get(ID); |
| 2095 local_folder_handle = new_entry.Get(META_HANDLE); | 2093 local_folder_handle = new_entry.Get(META_HANDLE); |
| 2096 new_entry.Put(IS_UNSYNCED, true); | 2094 new_entry.Put(IS_UNSYNCED, true); |
| 2097 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 2095 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
| 2098 ASSERT_TRUE(old.good()); | 2096 ASSERT_TRUE(old.good()); |
| 2099 WriteTestDataToEntry(&wtrans, &old); | 2097 WriteTestDataToEntry(&wtrans, &old); |
| 2100 } | 2098 } |
| 2101 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20); | 2099 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20); |
| 2102 mock_server_->set_conflict_all_commits(true); | 2100 mock_server_->set_conflict_all_commits(true); |
| 2103 syncer_->SyncShare(this); | 2101 syncer_->SyncShare(this); |
| 2104 syncer_events_.clear(); | 2102 syncer_events_.clear(); |
| 2105 } | 2103 } |
| 2106 | 2104 |
| 2107 // Circular links should be resolved by the server. | 2105 // Circular links should be resolved by the server. |
| 2108 TEST_F(SyncerTest, SiblingDirectoriesBecomeCircular) { | 2106 TEST_F(SyncerTest, SiblingDirectoriesBecomeCircular) { |
| 2109 // we don't currently resolve this. This test ensures we don't. | 2107 // we don't currently resolve this. This test ensures we don't. |
| 2110 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 2108 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 2111 CHECK(dir.good()); | 2109 CHECK(dir.good()); |
| 2112 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); | 2110 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); |
| 2113 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); | 2111 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); |
| 2114 syncer_->SyncShare(this); | 2112 syncer_->SyncShare(this); |
| 2115 { | 2113 { |
| 2116 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 2114 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 2117 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 2115 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
| 2118 ASSERT_TRUE(A.good()); | 2116 ASSERT_TRUE(A.good()); |
| 2119 A.Put(IS_UNSYNCED, true); | 2117 A.Put(IS_UNSYNCED, true); |
| 2120 ASSERT_TRUE(A.Put(PARENT_ID, ids_.FromNumber(2))); | 2118 ASSERT_TRUE(A.Put(PARENT_ID, ids_.FromNumber(2))); |
| 2121 ASSERT_TRUE(A.Put(NON_UNIQUE_NAME, PSTR("B"))); | 2119 ASSERT_TRUE(A.Put(NON_UNIQUE_NAME, "B")); |
| 2122 } | 2120 } |
| 2123 mock_server_->AddUpdateDirectory(2, 1, "A", 20, 20); | 2121 mock_server_->AddUpdateDirectory(2, 1, "A", 20, 20); |
| 2124 mock_server_->set_conflict_all_commits(true); | 2122 mock_server_->set_conflict_all_commits(true); |
| 2125 syncer_->SyncShare(this); | 2123 syncer_->SyncShare(this); |
| 2126 syncer_events_.clear(); | 2124 syncer_events_.clear(); |
| 2127 { | 2125 { |
| 2128 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 2126 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 2129 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 2127 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
| 2130 ASSERT_TRUE(A.good()); | 2128 ASSERT_TRUE(A.good()); |
| 2131 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); | 2129 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); |
| 2132 ASSERT_TRUE(B.good()); | 2130 ASSERT_TRUE(B.good()); |
| 2133 EXPECT_TRUE(A.Get(NON_UNIQUE_NAME) == PSTR("B")); | 2131 EXPECT_TRUE(A.Get(NON_UNIQUE_NAME) == "B"); |
| 2134 EXPECT_TRUE(B.Get(NON_UNIQUE_NAME) == PSTR("B")); | 2132 EXPECT_TRUE(B.Get(NON_UNIQUE_NAME) == "B"); |
| 2135 } | 2133 } |
| 2136 } | 2134 } |
| 2137 | 2135 |
| 2138 TEST_F(SyncerTest, ConflictSetClassificationError) { | 2136 TEST_F(SyncerTest, ConflictSetClassificationError) { |
| 2139 // This code used to cause a CHECK failure because we incorrectly thought | 2137 // This code used to cause a CHECK failure because we incorrectly thought |
| 2140 // a set was only unapplied updates. | 2138 // a set was only unapplied updates. |
| 2141 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 2139 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 2142 CHECK(dir.good()); | 2140 CHECK(dir.good()); |
| 2143 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); | 2141 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); |
| 2144 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); | 2142 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); |
| 2145 mock_server_->set_conflict_all_commits(true); | 2143 mock_server_->set_conflict_all_commits(true); |
| 2146 syncer_->SyncShare(this); | 2144 syncer_->SyncShare(this); |
| 2147 { | 2145 { |
| 2148 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 2146 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 2149 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 2147 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
| 2150 ASSERT_TRUE(A.good()); | 2148 ASSERT_TRUE(A.good()); |
| 2151 A.Put(IS_UNSYNCED, true); | 2149 A.Put(IS_UNSYNCED, true); |
| 2152 A.Put(IS_UNAPPLIED_UPDATE, true); | 2150 A.Put(IS_UNAPPLIED_UPDATE, true); |
| 2153 A.Put(SERVER_NON_UNIQUE_NAME, PSTR("B")); | 2151 A.Put(SERVER_NON_UNIQUE_NAME, "B"); |
| 2154 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); | 2152 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); |
| 2155 ASSERT_TRUE(B.good()); | 2153 ASSERT_TRUE(B.good()); |
| 2156 B.Put(IS_UNAPPLIED_UPDATE, true); | 2154 B.Put(IS_UNAPPLIED_UPDATE, true); |
| 2157 B.Put(SERVER_NON_UNIQUE_NAME, PSTR("A")); | 2155 B.Put(SERVER_NON_UNIQUE_NAME, "A"); |
| 2158 } | 2156 } |
| 2159 syncer_->SyncShare(this); | 2157 syncer_->SyncShare(this); |
| 2160 syncer_events_.clear(); | 2158 syncer_events_.clear(); |
| 2161 } | 2159 } |
| 2162 | 2160 |
| 2163 TEST_F(SyncerTest, SwapEntryNames) { | 2161 TEST_F(SyncerTest, SwapEntryNames) { |
| 2164 // Simple transaction test. | 2162 // Simple transaction test. |
| 2165 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 2163 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 2166 CHECK(dir.good()); | 2164 CHECK(dir.good()); |
| 2167 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); | 2165 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); |
| 2168 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); | 2166 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); |
| 2169 mock_server_->set_conflict_all_commits(true); | 2167 mock_server_->set_conflict_all_commits(true); |
| 2170 syncer_->SyncShare(this); | 2168 syncer_->SyncShare(this); |
| 2171 { | 2169 { |
| 2172 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 2170 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 2173 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 2171 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
| 2174 ASSERT_TRUE(A.good()); | 2172 ASSERT_TRUE(A.good()); |
| 2175 A.Put(IS_UNSYNCED, true); | 2173 A.Put(IS_UNSYNCED, true); |
| 2176 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); | 2174 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); |
| 2177 ASSERT_TRUE(B.good()); | 2175 ASSERT_TRUE(B.good()); |
| 2178 B.Put(IS_UNSYNCED, true); | 2176 B.Put(IS_UNSYNCED, true); |
| 2179 ASSERT_TRUE(A.Put(NON_UNIQUE_NAME, PSTR("C"))); | 2177 ASSERT_TRUE(A.Put(NON_UNIQUE_NAME, "C")); |
| 2180 ASSERT_TRUE(B.Put(NON_UNIQUE_NAME, PSTR("A"))); | 2178 ASSERT_TRUE(B.Put(NON_UNIQUE_NAME, "A")); |
| 2181 ASSERT_TRUE(A.Put(NON_UNIQUE_NAME, PSTR("B"))); | 2179 ASSERT_TRUE(A.Put(NON_UNIQUE_NAME, "B")); |
| 2182 } | 2180 } |
| 2183 syncer_->SyncShare(this); | 2181 syncer_->SyncShare(this); |
| 2184 syncer_events_.clear(); | 2182 syncer_events_.clear(); |
| 2185 } | 2183 } |
| 2186 | 2184 |
| 2187 TEST_F(SyncerTest, DualDeletionWithNewItemNameClash) { | 2185 TEST_F(SyncerTest, DualDeletionWithNewItemNameClash) { |
| 2188 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 2186 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 2189 CHECK(dir.good()); | 2187 CHECK(dir.good()); |
| 2190 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); | 2188 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); |
| 2191 mock_server_->AddUpdateBookmark(2, 0, "B", 10, 10); | 2189 mock_server_->AddUpdateBookmark(2, 0, "B", 10, 10); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2299 mock_server_->set_conflict_all_commits(true); | 2297 mock_server_->set_conflict_all_commits(true); |
| 2300 syncer_->SyncShare(this); | 2298 syncer_->SyncShare(this); |
| 2301 syncer_->SyncShare(this); | 2299 syncer_->SyncShare(this); |
| 2302 { | 2300 { |
| 2303 ReadTransaction trans(dir, __FILE__, __LINE__); | 2301 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 2304 | 2302 |
| 2305 Entry bob(&trans, GET_BY_ID, bob_id); | 2303 Entry bob(&trans, GET_BY_ID, bob_id); |
| 2306 ASSERT_TRUE(bob.good()); | 2304 ASSERT_TRUE(bob.good()); |
| 2307 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); | 2305 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); |
| 2308 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); | 2306 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); |
| 2309 EXPECT_TRUE(bob.Get(NON_UNIQUE_NAME) == PSTR("bob")); | 2307 EXPECT_TRUE(bob.Get(NON_UNIQUE_NAME) == "bob"); |
| 2310 EXPECT_NE(bob.Get(PARENT_ID), fred_id); | 2308 EXPECT_NE(bob.Get(PARENT_ID), fred_id); |
| 2311 | 2309 |
| 2312 // Entry was deleted and reborn. | 2310 // Entry was deleted and reborn. |
| 2313 Entry dead_fred(&trans, GET_BY_ID, fred_id); | 2311 Entry dead_fred(&trans, GET_BY_ID, fred_id); |
| 2314 EXPECT_FALSE(dead_fred.good()); | 2312 EXPECT_FALSE(dead_fred.good()); |
| 2315 | 2313 |
| 2316 // Reborn fred | 2314 // Reborn fred |
| 2317 Entry fred(&trans, GET_BY_ID, bob.Get(PARENT_ID)); | 2315 Entry fred(&trans, GET_BY_ID, bob.Get(PARENT_ID)); |
| 2318 ASSERT_TRUE(fred.good()); | 2316 ASSERT_TRUE(fred.good()); |
| 2319 EXPECT_TRUE(fred.Get(PARENT_ID) == trans.root_id()); | 2317 EXPECT_TRUE(fred.Get(PARENT_ID) == trans.root_id()); |
| 2320 EXPECT_EQ(PSTR("fred"), fred.Get(NON_UNIQUE_NAME)); | 2318 EXPECT_EQ("fred", fred.Get(NON_UNIQUE_NAME)); |
| 2321 EXPECT_TRUE(fred.Get(IS_UNSYNCED)); | 2319 EXPECT_TRUE(fred.Get(IS_UNSYNCED)); |
| 2322 EXPECT_FALSE(fred.Get(IS_UNAPPLIED_UPDATE)); | 2320 EXPECT_FALSE(fred.Get(IS_UNAPPLIED_UPDATE)); |
| 2323 } | 2321 } |
| 2324 syncer_events_.clear(); | 2322 syncer_events_.clear(); |
| 2325 } | 2323 } |
| 2326 | 2324 |
| 2327 // TODO(ncarter): This test is bogus, but it actually seems to hit an | 2325 // TODO(ncarter): This test is bogus, but it actually seems to hit an |
| 2328 // interesting case the 4th time SyncShare is called. | 2326 // interesting case the 4th time SyncShare is called. |
| 2329 // TODO(chron): The fourth time that SyncShare is called it crashes. | 2327 // TODO(chron): The fourth time that SyncShare is called it crashes. |
| 2330 // This seems to be due to a bug in the conflict set building logic. | 2328 // This seems to be due to a bug in the conflict set building logic. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2362 syncer_->SyncShare(this); | 2360 syncer_->SyncShare(this); |
| 2363 syncer_->SyncShare(this); | 2361 syncer_->SyncShare(this); |
| 2364 syncer_->SyncShare(this); | 2362 syncer_->SyncShare(this); |
| 2365 syncer_->SyncShare(this); | 2363 syncer_->SyncShare(this); |
| 2366 EXPECT_TRUE(0 == syncer_events_.size()); | 2364 EXPECT_TRUE(0 == syncer_events_.size()); |
| 2367 { | 2365 { |
| 2368 ReadTransaction trans(dir, __FILE__, __LINE__); | 2366 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 2369 Entry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); | 2367 Entry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); |
| 2370 ASSERT_TRUE(bob.good()); | 2368 ASSERT_TRUE(bob.good()); |
| 2371 Id fred_id = | 2369 Id fred_id = |
| 2372 GetOnlyEntryWithName(&trans, TestIdFactory::root(), PSTR("fred")); | 2370 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "fred"); |
| 2373 Entry fred(&trans, GET_BY_ID, fred_id); | 2371 Entry fred(&trans, GET_BY_ID, fred_id); |
| 2374 ASSERT_TRUE(fred.good()); | 2372 ASSERT_TRUE(fred.good()); |
| 2375 EXPECT_FALSE(fred.Get(IS_UNSYNCED)); | 2373 EXPECT_FALSE(fred.Get(IS_UNSYNCED)); |
| 2376 EXPECT_TRUE(fred.Get(IS_UNAPPLIED_UPDATE)); | 2374 EXPECT_TRUE(fred.Get(IS_UNAPPLIED_UPDATE)); |
| 2377 EXPECT_TRUE(bob.Get(PARENT_ID) == fred.Get(ID)); | 2375 EXPECT_TRUE(bob.Get(PARENT_ID) == fred.Get(ID)); |
| 2378 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); | 2376 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); |
| 2379 } | 2377 } |
| 2380 syncer_events_.clear(); | 2378 syncer_events_.clear(); |
| 2381 } | 2379 } |
| 2382 | 2380 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2413 ReadTransaction trans(dir, __FILE__, __LINE__); | 2411 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 2414 Entry bob(&trans, GET_BY_ID, bob_id); | 2412 Entry bob(&trans, GET_BY_ID, bob_id); |
| 2415 ASSERT_TRUE(bob.good()); | 2413 ASSERT_TRUE(bob.good()); |
| 2416 | 2414 |
| 2417 // Entry was deleted by server. We'll make a new one though with a new ID. | 2415 // Entry was deleted by server. We'll make a new one though with a new ID. |
| 2418 Entry dead_fred(&trans, GET_BY_ID, fred_id); | 2416 Entry dead_fred(&trans, GET_BY_ID, fred_id); |
| 2419 EXPECT_FALSE(dead_fred.good()); | 2417 EXPECT_FALSE(dead_fred.good()); |
| 2420 | 2418 |
| 2421 // Fred is reborn with a local ID. | 2419 // Fred is reborn with a local ID. |
| 2422 Entry fred(&trans, GET_BY_ID, bob.Get(PARENT_ID)); | 2420 Entry fred(&trans, GET_BY_ID, bob.Get(PARENT_ID)); |
| 2423 EXPECT_EQ(PSTR("fred"), fred.Get(NON_UNIQUE_NAME)); | 2421 EXPECT_EQ("fred", fred.Get(NON_UNIQUE_NAME)); |
| 2424 EXPECT_EQ(TestIdFactory::root(), fred.Get(PARENT_ID)); | 2422 EXPECT_EQ(TestIdFactory::root(), fred.Get(PARENT_ID)); |
| 2425 EXPECT_TRUE(fred.Get(IS_UNSYNCED)); | 2423 EXPECT_TRUE(fred.Get(IS_UNSYNCED)); |
| 2426 EXPECT_FALSE(fred.Get(ID).ServerKnows()); | 2424 EXPECT_FALSE(fred.Get(ID).ServerKnows()); |
| 2427 | 2425 |
| 2428 // Bob needs to update his parent. | 2426 // Bob needs to update his parent. |
| 2429 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); | 2427 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); |
| 2430 EXPECT_TRUE(bob.Get(PARENT_ID) == fred.Get(ID)); | 2428 EXPECT_TRUE(bob.Get(PARENT_ID) == fred.Get(ID)); |
| 2431 EXPECT_TRUE(fred.Get(PARENT_ID) == root_id_); | 2429 EXPECT_TRUE(fred.Get(PARENT_ID) == root_id_); |
| 2432 EXPECT_FALSE(fred.Get(IS_UNAPPLIED_UPDATE)); | 2430 EXPECT_FALSE(fred.Get(IS_UNAPPLIED_UPDATE)); |
| 2433 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); | 2431 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2490 mock_server_->AddUpdateDirectory(bob_id, TestIdFactory::root(), | 2488 mock_server_->AddUpdateDirectory(bob_id, TestIdFactory::root(), |
| 2491 "bob", 1, 10); | 2489 "bob", 1, 10); |
| 2492 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(), | 2490 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(), |
| 2493 "fred", 1, 10); | 2491 "fred", 1, 10); |
| 2494 syncer_->SyncShare(this); | 2492 syncer_->SyncShare(this); |
| 2495 { | 2493 { |
| 2496 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 2494 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 2497 MutableEntry fred(&trans, GET_BY_ID, fred_id); | 2495 MutableEntry fred(&trans, GET_BY_ID, fred_id); |
| 2498 ASSERT_TRUE(fred.good()); | 2496 ASSERT_TRUE(fred.good()); |
| 2499 fred.Put(IS_UNSYNCED, true); | 2497 fred.Put(IS_UNSYNCED, true); |
| 2500 fred.Put(NON_UNIQUE_NAME, PSTR("Alice")); | 2498 fred.Put(NON_UNIQUE_NAME, "Alice"); |
| 2501 } | 2499 } |
| 2502 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(), | 2500 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(), |
| 2503 "fred", 2, 20); | 2501 "fred", 2, 20); |
| 2504 mock_server_->SetLastUpdateDeleted(); | 2502 mock_server_->SetLastUpdateDeleted(); |
| 2505 mock_server_->set_conflict_all_commits(true); | 2503 mock_server_->set_conflict_all_commits(true); |
| 2506 // This test is a little brittle. We want to move the item into the folder | 2504 // This test is a little brittle. We want to move the item into the folder |
| 2507 // such that we think we're dealing with a simple conflict, but in reality | 2505 // such that we think we're dealing with a simple conflict, but in reality |
| 2508 // it's actually a conflict set. | 2506 // it's actually a conflict set. |
| 2509 move_bob_count_ = 2; | 2507 move_bob_count_ = 2; |
| 2510 mock_server_->SetMidCommitCallback( | 2508 mock_server_->SetMidCommitCallback( |
| 2511 NewCallback<FolderMoveDeleteRenameTest>(this, | 2509 NewCallback<FolderMoveDeleteRenameTest>(this, |
| 2512 &FolderMoveDeleteRenameTest::MoveBobIntoID2Runner)); | 2510 &FolderMoveDeleteRenameTest::MoveBobIntoID2Runner)); |
| 2513 syncer_->SyncShare(this); | 2511 syncer_->SyncShare(this); |
| 2514 syncer_->SyncShare(this); | 2512 syncer_->SyncShare(this); |
| 2515 syncer_->SyncShare(this); | 2513 syncer_->SyncShare(this); |
| 2516 { | 2514 { |
| 2517 ReadTransaction trans(dir, __FILE__, __LINE__); | 2515 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 2518 Entry bob(&trans, GET_BY_ID, bob_id); | 2516 Entry bob(&trans, GET_BY_ID, bob_id); |
| 2519 ASSERT_TRUE(bob.good()); | 2517 ASSERT_TRUE(bob.good()); |
| 2520 | 2518 |
| 2521 // Old entry is dead | 2519 // Old entry is dead |
| 2522 Entry dead_fred(&trans, GET_BY_ID, fred_id); | 2520 Entry dead_fred(&trans, GET_BY_ID, fred_id); |
| 2523 EXPECT_FALSE(dead_fred.good()); | 2521 EXPECT_FALSE(dead_fred.good()); |
| 2524 | 2522 |
| 2525 // New ID is created to fill parent folder, named correctly | 2523 // New ID is created to fill parent folder, named correctly |
| 2526 Entry alice(&trans, GET_BY_ID, bob.Get(PARENT_ID)); | 2524 Entry alice(&trans, GET_BY_ID, bob.Get(PARENT_ID)); |
| 2527 ASSERT_TRUE(alice.good()); | 2525 ASSERT_TRUE(alice.good()); |
| 2528 EXPECT_EQ(PSTR("Alice"), alice.Get(NON_UNIQUE_NAME)); | 2526 EXPECT_EQ("Alice", alice.Get(NON_UNIQUE_NAME)); |
| 2529 EXPECT_TRUE(alice.Get(IS_UNSYNCED)); | 2527 EXPECT_TRUE(alice.Get(IS_UNSYNCED)); |
| 2530 EXPECT_FALSE(alice.Get(ID).ServerKnows()); | 2528 EXPECT_FALSE(alice.Get(ID).ServerKnows()); |
| 2531 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); | 2529 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); |
| 2532 EXPECT_TRUE(bob.Get(PARENT_ID) == alice.Get(ID)); | 2530 EXPECT_TRUE(bob.Get(PARENT_ID) == alice.Get(ID)); |
| 2533 EXPECT_TRUE(alice.Get(PARENT_ID) == root_id_); | 2531 EXPECT_TRUE(alice.Get(PARENT_ID) == root_id_); |
| 2534 EXPECT_FALSE(alice.Get(IS_UNAPPLIED_UPDATE)); | 2532 EXPECT_FALSE(alice.Get(IS_UNAPPLIED_UPDATE)); |
| 2535 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); | 2533 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); |
| 2536 } | 2534 } |
| 2537 syncer_events_.clear(); | 2535 syncer_events_.clear(); |
| 2538 } | 2536 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2551 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(), | 2549 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(), |
| 2552 "fred", 1, 10); | 2550 "fred", 1, 10); |
| 2553 syncer_->SyncShare(this); | 2551 syncer_->SyncShare(this); |
| 2554 syncable::Id new_item_id; | 2552 syncable::Id new_item_id; |
| 2555 { | 2553 { |
| 2556 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 2554 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 2557 MutableEntry bob(&trans, GET_BY_ID, bob_id); | 2555 MutableEntry bob(&trans, GET_BY_ID, bob_id); |
| 2558 ASSERT_TRUE(bob.good()); | 2556 ASSERT_TRUE(bob.good()); |
| 2559 bob.Put(IS_UNSYNCED, true); | 2557 bob.Put(IS_UNSYNCED, true); |
| 2560 bob.Put(PARENT_ID, fred_id); | 2558 bob.Put(PARENT_ID, fred_id); |
| 2561 MutableEntry new_item(&trans, CREATE, fred_id, PSTR("new_item")); | 2559 MutableEntry new_item(&trans, CREATE, fred_id, "new_item"); |
| 2562 WriteTestDataToEntry(&trans, &new_item); | 2560 WriteTestDataToEntry(&trans, &new_item); |
| 2563 new_item_id = new_item.Get(ID); | 2561 new_item_id = new_item.Get(ID); |
| 2564 } | 2562 } |
| 2565 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(), | 2563 mock_server_->AddUpdateDirectory(fred_id, TestIdFactory::root(), |
| 2566 "fred", 2, 20); | 2564 "fred", 2, 20); |
| 2567 mock_server_->SetLastUpdateDeleted(); | 2565 mock_server_->SetLastUpdateDeleted(); |
| 2568 mock_server_->set_conflict_all_commits(true); | 2566 mock_server_->set_conflict_all_commits(true); |
| 2569 syncer_->SyncShare(this); | 2567 syncer_->SyncShare(this); |
| 2570 syncer_->SyncShare(this); | 2568 syncer_->SyncShare(this); |
| 2571 { | 2569 { |
| 2572 ReadTransaction trans(dir, __FILE__, __LINE__); | 2570 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 2573 | 2571 |
| 2574 Entry bob(&trans, GET_BY_ID, bob_id); | 2572 Entry bob(&trans, GET_BY_ID, bob_id); |
| 2575 ASSERT_TRUE(bob.good()); | 2573 ASSERT_TRUE(bob.good()); |
| 2576 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); | 2574 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); |
| 2577 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); | 2575 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); |
| 2578 EXPECT_NE(bob.Get(PARENT_ID), fred_id); | 2576 EXPECT_NE(bob.Get(PARENT_ID), fred_id); |
| 2579 | 2577 |
| 2580 // Was recreated. Old one shouldn't exist. | 2578 // Was recreated. Old one shouldn't exist. |
| 2581 Entry dead_fred(&trans, GET_BY_ID, fred_id); | 2579 Entry dead_fred(&trans, GET_BY_ID, fred_id); |
| 2582 EXPECT_FALSE(dead_fred.good()); | 2580 EXPECT_FALSE(dead_fred.good()); |
| 2583 | 2581 |
| 2584 Entry fred(&trans, GET_BY_ID, bob.Get(PARENT_ID)); | 2582 Entry fred(&trans, GET_BY_ID, bob.Get(PARENT_ID)); |
| 2585 ASSERT_TRUE(fred.good()); | 2583 ASSERT_TRUE(fred.good()); |
| 2586 EXPECT_TRUE(fred.Get(IS_UNSYNCED)); | 2584 EXPECT_TRUE(fred.Get(IS_UNSYNCED)); |
| 2587 EXPECT_FALSE(fred.Get(ID).ServerKnows()); | 2585 EXPECT_FALSE(fred.Get(ID).ServerKnows()); |
| 2588 EXPECT_EQ(PSTR("fred"), fred.Get(NON_UNIQUE_NAME)); | 2586 EXPECT_EQ("fred", fred.Get(NON_UNIQUE_NAME)); |
| 2589 EXPECT_FALSE(fred.Get(IS_UNAPPLIED_UPDATE)); | 2587 EXPECT_FALSE(fred.Get(IS_UNAPPLIED_UPDATE)); |
| 2590 EXPECT_TRUE(fred.Get(PARENT_ID) == root_id_); | 2588 EXPECT_TRUE(fred.Get(PARENT_ID) == root_id_); |
| 2591 | 2589 |
| 2592 Entry new_item(&trans, GET_BY_ID, new_item_id); | 2590 Entry new_item(&trans, GET_BY_ID, new_item_id); |
| 2593 ASSERT_TRUE(new_item.good()); | 2591 ASSERT_TRUE(new_item.good()); |
| 2594 EXPECT_EQ(new_item.Get(PARENT_ID), fred.Get(ID)); | 2592 EXPECT_EQ(new_item.Get(PARENT_ID), fred.Get(ID)); |
| 2595 } | 2593 } |
| 2596 syncer_events_.clear(); | 2594 syncer_events_.clear(); |
| 2597 } | 2595 } |
| 2598 | 2596 |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2946 Entry dead_alice(&trans, GET_BY_ID, alice_id); | 2944 Entry dead_alice(&trans, GET_BY_ID, alice_id); |
| 2947 EXPECT_FALSE(dead_alice.good()); | 2945 EXPECT_FALSE(dead_alice.good()); |
| 2948 EXPECT_NE(bob.Get(PARENT_ID), alice_id); | 2946 EXPECT_NE(bob.Get(PARENT_ID), alice_id); |
| 2949 | 2947 |
| 2950 // Newly born alice | 2948 // Newly born alice |
| 2951 Entry alice(&trans, GET_BY_ID, bob.Get(PARENT_ID)); | 2949 Entry alice(&trans, GET_BY_ID, bob.Get(PARENT_ID)); |
| 2952 ASSERT_TRUE(alice.good()); | 2950 ASSERT_TRUE(alice.good()); |
| 2953 EXPECT_FALSE(alice.Get(IS_UNAPPLIED_UPDATE)); | 2951 EXPECT_FALSE(alice.Get(IS_UNAPPLIED_UPDATE)); |
| 2954 EXPECT_TRUE(alice.Get(IS_UNSYNCED)); | 2952 EXPECT_TRUE(alice.Get(IS_UNSYNCED)); |
| 2955 EXPECT_FALSE(alice.Get(ID).ServerKnows()); | 2953 EXPECT_FALSE(alice.Get(ID).ServerKnows()); |
| 2956 EXPECT_TRUE(alice.Get(NON_UNIQUE_NAME) == PSTR("alice")); | 2954 EXPECT_TRUE(alice.Get(NON_UNIQUE_NAME) == "alice"); |
| 2957 | 2955 |
| 2958 // Alice needs a parent as well. Old parent should have been erased. | 2956 // Alice needs a parent as well. Old parent should have been erased. |
| 2959 Entry dead_fred(&trans, GET_BY_ID, fred_id); | 2957 Entry dead_fred(&trans, GET_BY_ID, fred_id); |
| 2960 EXPECT_FALSE(dead_fred.good()); | 2958 EXPECT_FALSE(dead_fred.good()); |
| 2961 EXPECT_NE(alice.Get(PARENT_ID), fred_id); | 2959 EXPECT_NE(alice.Get(PARENT_ID), fred_id); |
| 2962 | 2960 |
| 2963 Entry fred(&trans, GET_BY_ID, alice.Get(PARENT_ID)); | 2961 Entry fred(&trans, GET_BY_ID, alice.Get(PARENT_ID)); |
| 2964 ASSERT_TRUE(fred.good()); | 2962 ASSERT_TRUE(fred.good()); |
| 2965 EXPECT_EQ(fred.Get(PARENT_ID), TestIdFactory::root()); | 2963 EXPECT_EQ(fred.Get(PARENT_ID), TestIdFactory::root()); |
| 2966 EXPECT_TRUE(fred.Get(IS_UNSYNCED)); | 2964 EXPECT_TRUE(fred.Get(IS_UNSYNCED)); |
| 2967 EXPECT_FALSE(fred.Get(ID).ServerKnows()); | 2965 EXPECT_FALSE(fred.Get(ID).ServerKnows()); |
| 2968 EXPECT_FALSE(fred.Get(IS_UNAPPLIED_UPDATE)); | 2966 EXPECT_FALSE(fred.Get(IS_UNAPPLIED_UPDATE)); |
| 2969 EXPECT_TRUE(fred.Get(NON_UNIQUE_NAME) == PSTR("fred")); | 2967 EXPECT_TRUE(fred.Get(NON_UNIQUE_NAME) == "fred"); |
| 2970 } | 2968 } |
| 2971 syncer_events_.clear(); | 2969 syncer_events_.clear(); |
| 2972 } | 2970 } |
| 2973 | 2971 |
| 2974 TEST_F(SyncerTest, WeMovedSomethingIntoAFolderHierarchyServerHasDeleted2) { | 2972 TEST_F(SyncerTest, WeMovedSomethingIntoAFolderHierarchyServerHasDeleted2) { |
| 2975 // The difference here is that the hierarchy is not in the root. We have | 2973 // The difference here is that the hierarchy is not in the root. We have |
| 2976 // another entry that shouldn't be touched. | 2974 // another entry that shouldn't be touched. |
| 2977 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 2975 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 2978 CHECK(dir.good()); | 2976 CHECK(dir.good()); |
| 2979 | 2977 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3051 syncer_events_.clear(); | 3049 syncer_events_.clear(); |
| 3052 } | 3050 } |
| 3053 | 3051 |
| 3054 // This test is to reproduce a check failure. Sometimes we would get a bad ID | 3052 // This test is to reproduce a check failure. Sometimes we would get a bad ID |
| 3055 // back when creating an entry. | 3053 // back when creating an entry. |
| 3056 TEST_F(SyncerTest, DuplicateIDReturn) { | 3054 TEST_F(SyncerTest, DuplicateIDReturn) { |
| 3057 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 3055 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 3058 ASSERT_TRUE(dir.good()); | 3056 ASSERT_TRUE(dir.good()); |
| 3059 { | 3057 { |
| 3060 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 3058 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 3061 MutableEntry folder(&trans, CREATE, trans.root_id(), PSTR("bob")); | 3059 MutableEntry folder(&trans, CREATE, trans.root_id(), "bob"); |
| 3062 ASSERT_TRUE(folder.good()); | 3060 ASSERT_TRUE(folder.good()); |
| 3063 folder.Put(IS_UNSYNCED, true); | 3061 folder.Put(IS_UNSYNCED, true); |
| 3064 folder.Put(IS_DIR, true); | 3062 folder.Put(IS_DIR, true); |
| 3065 MutableEntry folder2(&trans, CREATE, trans.root_id(), PSTR("fred")); | 3063 MutableEntry folder2(&trans, CREATE, trans.root_id(), "fred"); |
| 3066 ASSERT_TRUE(folder2.good()); | 3064 ASSERT_TRUE(folder2.good()); |
| 3067 folder2.Put(IS_UNSYNCED, false); | 3065 folder2.Put(IS_UNSYNCED, false); |
| 3068 folder2.Put(IS_DIR, true); | 3066 folder2.Put(IS_DIR, true); |
| 3069 folder2.Put(BASE_VERSION, 3); | 3067 folder2.Put(BASE_VERSION, 3); |
| 3070 folder2.Put(ID, syncable::Id::CreateFromServerId("mock_server:10000")); | 3068 folder2.Put(ID, syncable::Id::CreateFromServerId("mock_server:10000")); |
| 3071 } | 3069 } |
| 3072 mock_server_->set_next_new_id(10000); | 3070 mock_server_->set_next_new_id(10000); |
| 3073 EXPECT_TRUE(1 == dir->unsynced_entity_count()); | 3071 EXPECT_TRUE(1 == dir->unsynced_entity_count()); |
| 3074 syncer_->SyncShare(this); // we get back a bad id in here (should never happe
n). | 3072 syncer_->SyncShare(this); // we get back a bad id in here (should never happe
n). |
| 3075 EXPECT_TRUE(1 == dir->unsynced_entity_count()); | 3073 EXPECT_TRUE(1 == dir->unsynced_entity_count()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3100 TEST_F(SyncerTest, ConflictResolverMergeOverwritesLocalEntry) { | 3098 TEST_F(SyncerTest, ConflictResolverMergeOverwritesLocalEntry) { |
| 3101 // This test would die because it would rename a entry to a name that was | 3099 // This test would die because it would rename a entry to a name that was |
| 3102 // taken in the namespace | 3100 // taken in the namespace |
| 3103 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 3101 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 3104 CHECK(dir.good()); | 3102 CHECK(dir.good()); |
| 3105 | 3103 |
| 3106 ConflictSet conflict_set; | 3104 ConflictSet conflict_set; |
| 3107 { | 3105 { |
| 3108 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 3106 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 3109 | 3107 |
| 3110 MutableEntry local_deleted(&trans, CREATE, trans.root_id(), PSTR("name")); | 3108 MutableEntry local_deleted(&trans, CREATE, trans.root_id(), "name"); |
| 3111 local_deleted.Put(ID, ids_.FromNumber(1)); | 3109 local_deleted.Put(ID, ids_.FromNumber(1)); |
| 3112 local_deleted.Put(BASE_VERSION, 1); | 3110 local_deleted.Put(BASE_VERSION, 1); |
| 3113 local_deleted.Put(IS_DEL, true); | 3111 local_deleted.Put(IS_DEL, true); |
| 3114 local_deleted.Put(IS_UNSYNCED, true); | 3112 local_deleted.Put(IS_UNSYNCED, true); |
| 3115 | 3113 |
| 3116 MutableEntry in_the_way(&trans, CREATE, trans.root_id(), PSTR("name")); | 3114 MutableEntry in_the_way(&trans, CREATE, trans.root_id(), "name"); |
| 3117 in_the_way.Put(ID, ids_.FromNumber(2)); | 3115 in_the_way.Put(ID, ids_.FromNumber(2)); |
| 3118 in_the_way.Put(BASE_VERSION, 1); | 3116 in_the_way.Put(BASE_VERSION, 1); |
| 3119 | 3117 |
| 3120 MutableEntry update(&trans, CREATE_NEW_UPDATE_ITEM, ids_.FromNumber(3)); | 3118 MutableEntry update(&trans, CREATE_NEW_UPDATE_ITEM, ids_.FromNumber(3)); |
| 3121 update.Put(BASE_VERSION, 1); | 3119 update.Put(BASE_VERSION, 1); |
| 3122 update.Put(SERVER_NON_UNIQUE_NAME, PSTR("name")); | 3120 update.Put(SERVER_NON_UNIQUE_NAME, "name"); |
| 3123 update.Put(PARENT_ID, ids_.FromNumber(0)); | 3121 update.Put(PARENT_ID, ids_.FromNumber(0)); |
| 3124 update.Put(IS_UNAPPLIED_UPDATE, true); | 3122 update.Put(IS_UNAPPLIED_UPDATE, true); |
| 3125 | 3123 |
| 3126 conflict_set.push_back(ids_.FromNumber(1)); | 3124 conflict_set.push_back(ids_.FromNumber(1)); |
| 3127 conflict_set.push_back(ids_.FromNumber(3)); | 3125 conflict_set.push_back(ids_.FromNumber(3)); |
| 3128 } | 3126 } |
| 3129 { | 3127 { |
| 3130 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 3128 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 3131 context_->resolver()->ProcessConflictSet(&trans, &conflict_set, 50); | 3129 context_->resolver()->ProcessConflictSet(&trans, &conflict_set, 50); |
| 3132 } | 3130 } |
| 3133 } | 3131 } |
| 3134 | 3132 |
| 3135 TEST_F(SyncerTest, ConflictResolverMergesLocalDeleteAndServerUpdate) { | 3133 TEST_F(SyncerTest, ConflictResolverMergesLocalDeleteAndServerUpdate) { |
| 3136 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 3134 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 3137 CHECK(dir.good()); | 3135 CHECK(dir.good()); |
| 3138 | 3136 |
| 3139 { | 3137 { |
| 3140 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 3138 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 3141 | 3139 |
| 3142 MutableEntry local_deleted(&trans, CREATE, trans.root_id(), PSTR("name")); | 3140 MutableEntry local_deleted(&trans, CREATE, trans.root_id(), "name"); |
| 3143 local_deleted.Put(ID, ids_.FromNumber(1)); | 3141 local_deleted.Put(ID, ids_.FromNumber(1)); |
| 3144 local_deleted.Put(BASE_VERSION, 1); | 3142 local_deleted.Put(BASE_VERSION, 1); |
| 3145 local_deleted.Put(IS_DEL, true); | 3143 local_deleted.Put(IS_DEL, true); |
| 3146 local_deleted.Put(IS_DIR, false); | 3144 local_deleted.Put(IS_DIR, false); |
| 3147 local_deleted.Put(IS_UNSYNCED, true); | 3145 local_deleted.Put(IS_UNSYNCED, true); |
| 3148 local_deleted.Put(IS_BOOKMARK_OBJECT, true); | 3146 local_deleted.Put(IS_BOOKMARK_OBJECT, true); |
| 3149 } | 3147 } |
| 3150 | 3148 |
| 3151 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10); | 3149 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10); |
| 3152 | 3150 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3168 // See what happens if the IS_DIR bit gets flipped. This can cause us | 3166 // See what happens if the IS_DIR bit gets flipped. This can cause us |
| 3169 // all kinds of disasters. | 3167 // all kinds of disasters. |
| 3170 TEST_F(SyncerTest, UpdateFlipsTheFolderBit) { | 3168 TEST_F(SyncerTest, UpdateFlipsTheFolderBit) { |
| 3171 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 3169 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 3172 CHECK(dir.good()); | 3170 CHECK(dir.good()); |
| 3173 | 3171 |
| 3174 // Local object: a deleted directory (container), revision 1, unsynced. | 3172 // Local object: a deleted directory (container), revision 1, unsynced. |
| 3175 { | 3173 { |
| 3176 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 3174 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 3177 | 3175 |
| 3178 MutableEntry local_deleted(&trans, CREATE, trans.root_id(), PSTR("name")); | 3176 MutableEntry local_deleted(&trans, CREATE, trans.root_id(), "name"); |
| 3179 local_deleted.Put(ID, ids_.FromNumber(1)); | 3177 local_deleted.Put(ID, ids_.FromNumber(1)); |
| 3180 local_deleted.Put(BASE_VERSION, 1); | 3178 local_deleted.Put(BASE_VERSION, 1); |
| 3181 local_deleted.Put(IS_DEL, true); | 3179 local_deleted.Put(IS_DEL, true); |
| 3182 local_deleted.Put(IS_DIR, true); | 3180 local_deleted.Put(IS_DIR, true); |
| 3183 local_deleted.Put(IS_UNSYNCED, true); | 3181 local_deleted.Put(IS_UNSYNCED, true); |
| 3184 } | 3182 } |
| 3185 | 3183 |
| 3186 // Server update: entry-type object (not a container), revision 10. | 3184 // Server update: entry-type object (not a container), revision 10. |
| 3187 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10); | 3185 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10); |
| 3188 | 3186 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3237 // Merge conflict resolution will merge a new local entry with another entry | 3235 // Merge conflict resolution will merge a new local entry with another entry |
| 3238 // that needs updates, resulting in CHECK. | 3236 // that needs updates, resulting in CHECK. |
| 3239 TEST_F(SyncerTest, MergingExistingItems) { | 3237 TEST_F(SyncerTest, MergingExistingItems) { |
| 3240 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 3238 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 3241 CHECK(dir.good()); | 3239 CHECK(dir.good()); |
| 3242 mock_server_->set_conflict_all_commits(true); | 3240 mock_server_->set_conflict_all_commits(true); |
| 3243 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10); | 3241 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10); |
| 3244 syncer_->SyncShare(this); | 3242 syncer_->SyncShare(this); |
| 3245 { | 3243 { |
| 3246 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 3244 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 3247 MutableEntry entry(&trans, CREATE, trans.root_id(), PSTR("Copy of base")); | 3245 MutableEntry entry(&trans, CREATE, trans.root_id(), "Copy of base"); |
| 3248 WriteTestDataToEntry(&trans, &entry); | 3246 WriteTestDataToEntry(&trans, &entry); |
| 3249 } | 3247 } |
| 3250 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50); | 3248 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50); |
| 3251 SyncRepeatedlyToTriggerConflictResolution(session_.get()); | 3249 SyncRepeatedlyToTriggerConflictResolution(session_.get()); |
| 3252 } | 3250 } |
| 3253 | 3251 |
| 3254 // In this test a long changelog contains a child at the start of the changelog | 3252 // In this test a long changelog contains a child at the start of the changelog |
| 3255 // and a parent at the end. While these updates are in progress the client would | 3253 // and a parent at the end. While these updates are in progress the client would |
| 3256 // appear stuck. | 3254 // appear stuck. |
| 3257 TEST_F(SyncerTest, LongChangelistWithApplicationConflict) { | 3255 TEST_F(SyncerTest, LongChangelistWithApplicationConflict) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3290 mock_server_->SetChangesRemaining(0); | 3288 mock_server_->SetChangesRemaining(0); |
| 3291 LoopSyncShare(syncer_); | 3289 LoopSyncShare(syncer_); |
| 3292 LoopSyncShare(syncer_); | 3290 LoopSyncShare(syncer_); |
| 3293 // Check that everything is as expected after the commit. | 3291 // Check that everything is as expected after the commit. |
| 3294 { | 3292 { |
| 3295 ReadTransaction trans(dir, __FILE__, __LINE__); | 3293 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 3296 Entry entry(&trans, GET_BY_ID, folder_id); | 3294 Entry entry(&trans, GET_BY_ID, folder_id); |
| 3297 ASSERT_TRUE(entry.good()); | 3295 ASSERT_TRUE(entry.good()); |
| 3298 Entry child(&trans, GET_BY_ID, stuck_entry_id); | 3296 Entry child(&trans, GET_BY_ID, stuck_entry_id); |
| 3299 EXPECT_EQ(entry.Get(ID), child.Get(PARENT_ID)); | 3297 EXPECT_EQ(entry.Get(ID), child.Get(PARENT_ID)); |
| 3300 EXPECT_EQ(PSTR("stuck"), child.Get(NON_UNIQUE_NAME)); | 3298 EXPECT_EQ("stuck", child.Get(NON_UNIQUE_NAME)); |
| 3301 EXPECT_TRUE(child.good()); | 3299 EXPECT_TRUE(child.good()); |
| 3302 } | 3300 } |
| 3303 } | 3301 } |
| 3304 | 3302 |
| 3305 TEST_F(SyncerTest, DontMergeTwoExistingItems) { | 3303 TEST_F(SyncerTest, DontMergeTwoExistingItems) { |
| 3306 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 3304 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 3307 EXPECT_TRUE(dir.good()); | 3305 EXPECT_TRUE(dir.good()); |
| 3308 mock_server_->set_conflict_all_commits(true); | 3306 mock_server_->set_conflict_all_commits(true); |
| 3309 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10); | 3307 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10); |
| 3310 mock_server_->AddUpdateBookmark(2, 0, "base2", 10, 10); | 3308 mock_server_->AddUpdateBookmark(2, 0, "base2", 10, 10); |
| 3311 syncer_->SyncShare(this); | 3309 syncer_->SyncShare(this); |
| 3312 { | 3310 { |
| 3313 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 3311 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 3314 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); | 3312 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); |
| 3315 ASSERT_TRUE(entry.good()); | 3313 ASSERT_TRUE(entry.good()); |
| 3316 EXPECT_TRUE(entry.Put(NON_UNIQUE_NAME, PSTR("Copy of base"))); | 3314 EXPECT_TRUE(entry.Put(NON_UNIQUE_NAME, "Copy of base")); |
| 3317 entry.Put(IS_UNSYNCED, true); | 3315 entry.Put(IS_UNSYNCED, true); |
| 3318 } | 3316 } |
| 3319 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50); | 3317 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50); |
| 3320 SyncRepeatedlyToTriggerConflictResolution(session_.get()); | 3318 SyncRepeatedlyToTriggerConflictResolution(session_.get()); |
| 3321 { | 3319 { |
| 3322 ReadTransaction trans(dir, __FILE__, __LINE__); | 3320 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 3323 Entry entry1(&trans, GET_BY_ID, ids_.FromNumber(1)); | 3321 Entry entry1(&trans, GET_BY_ID, ids_.FromNumber(1)); |
| 3324 EXPECT_FALSE(entry1.Get(IS_UNAPPLIED_UPDATE)); | 3322 EXPECT_FALSE(entry1.Get(IS_UNAPPLIED_UPDATE)); |
| 3325 EXPECT_FALSE(entry1.Get(IS_UNSYNCED)); | 3323 EXPECT_FALSE(entry1.Get(IS_UNSYNCED)); |
| 3326 EXPECT_FALSE(entry1.Get(IS_DEL)); | 3324 EXPECT_FALSE(entry1.Get(IS_DEL)); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3432 | 3430 |
| 3433 mock_server_->AddUpdateDirectory(in_root_id, TestIdFactory::root(), | 3431 mock_server_->AddUpdateDirectory(in_root_id, TestIdFactory::root(), |
| 3434 "in_root_name", 2, 2); | 3432 "in_root_name", 2, 2); |
| 3435 mock_server_->AddUpdateDirectory(in_in_root_id, in_root_id, | 3433 mock_server_->AddUpdateDirectory(in_in_root_id, in_root_id, |
| 3436 "in_in_root_name", 3, 3); | 3434 "in_in_root_name", 3, 3); |
| 3437 syncer_->SyncShare(this); | 3435 syncer_->SyncShare(this); |
| 3438 { | 3436 { |
| 3439 ReadTransaction trans(dir, __FILE__, __LINE__); | 3437 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 3440 Entry in_root(&trans, GET_BY_ID, in_root_id); | 3438 Entry in_root(&trans, GET_BY_ID, in_root_id); |
| 3441 ASSERT_TRUE(in_root.good()); | 3439 ASSERT_TRUE(in_root.good()); |
| 3442 EXPECT_EQ(PSTR("in_root_name"), in_root.Get(NON_UNIQUE_NAME)); | 3440 EXPECT_EQ("in_root_name", in_root.Get(NON_UNIQUE_NAME)); |
| 3443 EXPECT_EQ(TestIdFactory::root(), in_root.Get(PARENT_ID)); | 3441 EXPECT_EQ(TestIdFactory::root(), in_root.Get(PARENT_ID)); |
| 3444 | 3442 |
| 3445 Entry in_in_root(&trans, GET_BY_ID, in_in_root_id); | 3443 Entry in_in_root(&trans, GET_BY_ID, in_in_root_id); |
| 3446 ASSERT_TRUE(in_in_root.good()); | 3444 ASSERT_TRUE(in_in_root.good()); |
| 3447 EXPECT_EQ(PSTR("in_in_root_name"), in_in_root.Get(NON_UNIQUE_NAME)); | 3445 EXPECT_EQ("in_in_root_name", in_in_root.Get(NON_UNIQUE_NAME)); |
| 3448 EXPECT_EQ(in_root_id, in_in_root.Get(PARENT_ID)); | 3446 EXPECT_EQ(in_root_id, in_in_root.Get(PARENT_ID)); |
| 3449 } | 3447 } |
| 3450 } | 3448 } |
| 3451 | 3449 |
| 3452 TEST_F(SyncerTest, DirectoryCommitTest) { | 3450 TEST_F(SyncerTest, DirectoryCommitTest) { |
| 3453 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 3451 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 3454 CHECK(dir.good()); | 3452 CHECK(dir.good()); |
| 3455 | 3453 |
| 3456 syncable::Id in_root_id, in_dir_id; | 3454 syncable::Id in_root_id, in_dir_id; |
| 3457 int64 foo_metahandle; | 3455 int64 foo_metahandle; |
| 3458 int64 bar_metahandle; | 3456 int64 bar_metahandle; |
| 3459 | 3457 |
| 3460 { | 3458 { |
| 3461 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 3459 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 3462 MutableEntry parent(&wtrans, syncable::CREATE, root_id_, PSTR("foo")); | 3460 MutableEntry parent(&wtrans, syncable::CREATE, root_id_, "foo"); |
| 3463 ASSERT_TRUE(parent.good()); | 3461 ASSERT_TRUE(parent.good()); |
| 3464 parent.Put(syncable::IS_UNSYNCED, true); | 3462 parent.Put(syncable::IS_UNSYNCED, true); |
| 3465 parent.Put(syncable::IS_DIR, true); | 3463 parent.Put(syncable::IS_DIR, true); |
| 3466 in_root_id = parent.Get(syncable::ID); | 3464 in_root_id = parent.Get(syncable::ID); |
| 3467 foo_metahandle = parent.Get(META_HANDLE); | 3465 foo_metahandle = parent.Get(META_HANDLE); |
| 3468 | 3466 |
| 3469 MutableEntry child(&wtrans, syncable::CREATE, parent.Get(ID), PSTR("bar")); | 3467 MutableEntry child(&wtrans, syncable::CREATE, parent.Get(ID), "bar"); |
| 3470 ASSERT_TRUE(child.good()); | 3468 ASSERT_TRUE(child.good()); |
| 3471 child.Put(syncable::IS_UNSYNCED, true); | 3469 child.Put(syncable::IS_UNSYNCED, true); |
| 3472 child.Put(syncable::IS_DIR, true); | 3470 child.Put(syncable::IS_DIR, true); |
| 3473 bar_metahandle = child.Get(META_HANDLE); | 3471 bar_metahandle = child.Get(META_HANDLE); |
| 3474 in_dir_id = parent.Get(syncable::ID); | 3472 in_dir_id = parent.Get(syncable::ID); |
| 3475 } | 3473 } |
| 3476 syncer_->SyncShare(this); | 3474 syncer_->SyncShare(this); |
| 3477 { | 3475 { |
| 3478 ReadTransaction trans(dir, __FILE__, __LINE__); | 3476 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 3479 Entry fail_by_old_id_entry(&trans, GET_BY_ID, in_root_id); | 3477 Entry fail_by_old_id_entry(&trans, GET_BY_ID, in_root_id); |
| 3480 ASSERT_FALSE(fail_by_old_id_entry.good()); | 3478 ASSERT_FALSE(fail_by_old_id_entry.good()); |
| 3481 | 3479 |
| 3482 Entry foo_entry(&trans, GET_BY_HANDLE, foo_metahandle); | 3480 Entry foo_entry(&trans, GET_BY_HANDLE, foo_metahandle); |
| 3483 ASSERT_TRUE(foo_entry.good()); | 3481 ASSERT_TRUE(foo_entry.good()); |
| 3484 EXPECT_EQ(PSTR("foo"), foo_entry.Get(NON_UNIQUE_NAME)); | 3482 EXPECT_EQ("foo", foo_entry.Get(NON_UNIQUE_NAME)); |
| 3485 EXPECT_NE(foo_entry.Get(syncable::ID), in_root_id); | 3483 EXPECT_NE(foo_entry.Get(syncable::ID), in_root_id); |
| 3486 | 3484 |
| 3487 Entry bar_entry(&trans, GET_BY_HANDLE, bar_metahandle); | 3485 Entry bar_entry(&trans, GET_BY_HANDLE, bar_metahandle); |
| 3488 ASSERT_TRUE(bar_entry.good()); | 3486 ASSERT_TRUE(bar_entry.good()); |
| 3489 EXPECT_EQ(PSTR("bar"), bar_entry.Get(NON_UNIQUE_NAME)); | 3487 EXPECT_EQ("bar", bar_entry.Get(NON_UNIQUE_NAME)); |
| 3490 EXPECT_NE(bar_entry.Get(syncable::ID), in_dir_id); | 3488 EXPECT_NE(bar_entry.Get(syncable::ID), in_dir_id); |
| 3491 EXPECT_EQ(foo_entry.Get(syncable::ID), bar_entry.Get(PARENT_ID)); | 3489 EXPECT_EQ(foo_entry.Get(syncable::ID), bar_entry.Get(PARENT_ID)); |
| 3492 } | 3490 } |
| 3493 } | 3491 } |
| 3494 | 3492 |
| 3495 TEST_F(SyncerTest, ConflictSetSizeReducedToOne) { | 3493 TEST_F(SyncerTest, ConflictSetSizeReducedToOne) { |
| 3496 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 3494 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 3497 CHECK(dir.good()); | 3495 CHECK(dir.good()); |
| 3498 | 3496 |
| 3499 syncable::Id in_root_id = ids_.NewServerId(); | 3497 syncable::Id in_root_id = ids_.NewServerId(); |
| 3500 | 3498 |
| 3501 mock_server_->AddUpdateBookmark(in_root_id, TestIdFactory::root(), | 3499 mock_server_->AddUpdateBookmark(in_root_id, TestIdFactory::root(), |
| 3502 "in_root", 1, 1); | 3500 "in_root", 1, 1); |
| 3503 syncer_->SyncShare(this); | 3501 syncer_->SyncShare(this); |
| 3504 { | 3502 { |
| 3505 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 3503 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 3506 MutableEntry oentry(&trans, GET_BY_ID, in_root_id); | 3504 MutableEntry oentry(&trans, GET_BY_ID, in_root_id); |
| 3507 ASSERT_TRUE(oentry.good()); | 3505 ASSERT_TRUE(oentry.good()); |
| 3508 oentry.Put(NON_UNIQUE_NAME, PSTR("old_in_root")); | 3506 oentry.Put(NON_UNIQUE_NAME, "old_in_root"); |
| 3509 WriteTestDataToEntry(&trans, &oentry); | 3507 WriteTestDataToEntry(&trans, &oentry); |
| 3510 MutableEntry entry(&trans, CREATE, trans.root_id(), PSTR("in_root")); | 3508 MutableEntry entry(&trans, CREATE, trans.root_id(), "in_root"); |
| 3511 ASSERT_TRUE(entry.good()); | 3509 ASSERT_TRUE(entry.good()); |
| 3512 WriteTestDataToEntry(&trans, &entry); | 3510 WriteTestDataToEntry(&trans, &entry); |
| 3513 } | 3511 } |
| 3514 mock_server_->set_conflict_all_commits(true); | 3512 mock_server_->set_conflict_all_commits(true); |
| 3515 // This SyncShare call used to result in a CHECK failure. | 3513 // This SyncShare call used to result in a CHECK failure. |
| 3516 syncer_->SyncShare(this); | 3514 syncer_->SyncShare(this); |
| 3517 syncer_events_.clear(); | 3515 syncer_events_.clear(); |
| 3518 } | 3516 } |
| 3519 | 3517 |
| 3520 TEST_F(SyncerTest, TestClientCommand) { | 3518 TEST_F(SyncerTest, TestClientCommand) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3558 "folder_two", 1, 1); | 3556 "folder_two", 1, 1); |
| 3559 syncer_->SyncShare(this); | 3557 syncer_->SyncShare(this); |
| 3560 { | 3558 { |
| 3561 // A moved entry should send an old parent. | 3559 // A moved entry should send an old parent. |
| 3562 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 3560 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
| 3563 MutableEntry entry(&trans, GET_BY_ID, folder_one_id); | 3561 MutableEntry entry(&trans, GET_BY_ID, folder_one_id); |
| 3564 ASSERT_TRUE(entry.good()); | 3562 ASSERT_TRUE(entry.good()); |
| 3565 entry.Put(PARENT_ID, folder_two_id); | 3563 entry.Put(PARENT_ID, folder_two_id); |
| 3566 entry.Put(IS_UNSYNCED, true); | 3564 entry.Put(IS_UNSYNCED, true); |
| 3567 // A new entry should send no parent. | 3565 // A new entry should send no parent. |
| 3568 MutableEntry create(&trans, CREATE, trans.root_id(), PSTR("new_folder")); | 3566 MutableEntry create(&trans, CREATE, trans.root_id(), "new_folder"); |
| 3569 create.Put(IS_UNSYNCED, true); | 3567 create.Put(IS_UNSYNCED, true); |
| 3570 } | 3568 } |
| 3571 syncer_->SyncShare(this); | 3569 syncer_->SyncShare(this); |
| 3572 const sync_pb::CommitMessage& commit = mock_server_->last_sent_commit(); | 3570 const sync_pb::CommitMessage& commit = mock_server_->last_sent_commit(); |
| 3573 ASSERT_TRUE(2 == commit.entries_size()); | 3571 ASSERT_TRUE(2 == commit.entries_size()); |
| 3574 EXPECT_TRUE(commit.entries(0).parent_id_string() == "2"); | 3572 EXPECT_TRUE(commit.entries(0).parent_id_string() == "2"); |
| 3575 EXPECT_TRUE(commit.entries(0).old_parent_id() == "0"); | 3573 EXPECT_TRUE(commit.entries(0).old_parent_id() == "0"); |
| 3576 EXPECT_FALSE(commit.entries(1).has_old_parent_id()); | 3574 EXPECT_FALSE(commit.entries(1).has_old_parent_id()); |
| 3577 } | 3575 } |
| 3578 | 3576 |
| 3579 TEST_F(SyncerTest, Test64BitVersionSupport) { | 3577 TEST_F(SyncerTest, Test64BitVersionSupport) { |
| 3580 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 3578 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 3581 CHECK(dir.good()); | 3579 CHECK(dir.good()); |
| 3582 int64 really_big_int = std::numeric_limits<int64>::max() - 12; | 3580 int64 really_big_int = std::numeric_limits<int64>::max() - 12; |
| 3583 const PathString name(PSTR("ringo's dang orang ran rings around my o-ring")); | 3581 const string name("ringo's dang orang ran rings around my o-ring"); |
| 3584 int64 item_metahandle; | 3582 int64 item_metahandle; |
| 3585 | 3583 |
| 3586 // Try writing max int64 to the version fields of a meta entry. | 3584 // Try writing max int64 to the version fields of a meta entry. |
| 3587 { | 3585 { |
| 3588 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 3586 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 3589 MutableEntry entry(&wtrans, syncable::CREATE, wtrans.root_id(), name); | 3587 MutableEntry entry(&wtrans, syncable::CREATE, wtrans.root_id(), name); |
| 3590 ASSERT_TRUE(entry.good()); | 3588 ASSERT_TRUE(entry.good()); |
| 3591 entry.Put(syncable::BASE_VERSION, really_big_int); | 3589 entry.Put(syncable::BASE_VERSION, really_big_int); |
| 3592 entry.Put(syncable::SERVER_VERSION, really_big_int); | 3590 entry.Put(syncable::SERVER_VERSION, really_big_int); |
| 3593 entry.Put(syncable::ID, ids_.NewServerId()); | 3591 entry.Put(syncable::ID, ids_.NewServerId()); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3719 syncer_->SyncShare(this); | 3717 syncer_->SyncShare(this); |
| 3720 mock_server_->AddUpdateBookmark(id2, root, "foo2", 1, 10); | 3718 mock_server_->AddUpdateBookmark(id2, root, "foo2", 1, 10); |
| 3721 syncer_->SyncShare(this); // Now just don't explode. | 3719 syncer_->SyncShare(this); // Now just don't explode. |
| 3722 } | 3720 } |
| 3723 | 3721 |
| 3724 TEST_F(SyncerTest, SingletonTagUpdates) { | 3722 TEST_F(SyncerTest, SingletonTagUpdates) { |
| 3725 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 3723 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 3726 EXPECT_TRUE(dir.good()); | 3724 EXPECT_TRUE(dir.good()); |
| 3727 // As a hurdle, introduce an item whose name is the same as the tag value | 3725 // As a hurdle, introduce an item whose name is the same as the tag value |
| 3728 // we'll use later. | 3726 // we'll use later. |
| 3729 int64 hurdle_handle = CreateUnsyncedDirectory(PSTR("bob"), "id_bob"); | 3727 int64 hurdle_handle = CreateUnsyncedDirectory("bob", "id_bob"); |
| 3730 { | 3728 { |
| 3731 ReadTransaction trans(dir, __FILE__, __LINE__); | 3729 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 3732 Entry hurdle(&trans, GET_BY_HANDLE, hurdle_handle); | 3730 Entry hurdle(&trans, GET_BY_HANDLE, hurdle_handle); |
| 3733 ASSERT_TRUE(hurdle.good()); | 3731 ASSERT_TRUE(hurdle.good()); |
| 3734 ASSERT_TRUE(!hurdle.Get(IS_DEL)); | 3732 ASSERT_TRUE(!hurdle.Get(IS_DEL)); |
| 3735 ASSERT_TRUE(hurdle.Get(SINGLETON_TAG).empty()); | 3733 ASSERT_TRUE(hurdle.Get(SINGLETON_TAG).empty()); |
| 3736 ASSERT_TRUE(hurdle.Get(NON_UNIQUE_NAME) == PSTR("bob")); | 3734 ASSERT_TRUE(hurdle.Get(NON_UNIQUE_NAME) == "bob"); |
| 3737 | 3735 |
| 3738 // Try to lookup by the tagname. These should fail. | 3736 // Try to lookup by the tagname. These should fail. |
| 3739 Entry tag_alpha(&trans, GET_BY_TAG, PSTR("alpha")); | 3737 Entry tag_alpha(&trans, GET_BY_TAG, "alpha"); |
| 3740 EXPECT_FALSE(tag_alpha.good()); | 3738 EXPECT_FALSE(tag_alpha.good()); |
| 3741 Entry tag_bob(&trans, GET_BY_TAG, PSTR("bob")); | 3739 Entry tag_bob(&trans, GET_BY_TAG, "bob"); |
| 3742 EXPECT_FALSE(tag_bob.good()); | 3740 EXPECT_FALSE(tag_bob.good()); |
| 3743 } | 3741 } |
| 3744 | 3742 |
| 3745 // Now download some tagged items as updates. | 3743 // Now download some tagged items as updates. |
| 3746 mock_server_->AddUpdateDirectory(1, 0, "update1", 1, 10); | 3744 mock_server_->AddUpdateDirectory(1, 0, "update1", 1, 10); |
| 3747 mock_server_->SetLastUpdateSingletonTag("alpha"); | 3745 mock_server_->SetLastUpdateSingletonTag("alpha"); |
| 3748 mock_server_->AddUpdateDirectory(2, 0, "update2", 2, 20); | 3746 mock_server_->AddUpdateDirectory(2, 0, "update2", 2, 20); |
| 3749 mock_server_->SetLastUpdateSingletonTag("bob"); | 3747 mock_server_->SetLastUpdateSingletonTag("bob"); |
| 3750 syncer_->SyncShare(this); | 3748 syncer_->SyncShare(this); |
| 3751 | 3749 |
| 3752 { | 3750 { |
| 3753 ReadTransaction trans(dir, __FILE__, __LINE__); | 3751 ReadTransaction trans(dir, __FILE__, __LINE__); |
| 3754 | 3752 |
| 3755 // The new items should be applied as new entries, and we should be able | 3753 // The new items should be applied as new entries, and we should be able |
| 3756 // to look them up by their tag values. | 3754 // to look them up by their tag values. |
| 3757 Entry tag_alpha(&trans, GET_BY_TAG, PSTR("alpha")); | 3755 Entry tag_alpha(&trans, GET_BY_TAG, "alpha"); |
| 3758 ASSERT_TRUE(tag_alpha.good()); | 3756 ASSERT_TRUE(tag_alpha.good()); |
| 3759 ASSERT_TRUE(!tag_alpha.Get(IS_DEL)); | 3757 ASSERT_TRUE(!tag_alpha.Get(IS_DEL)); |
| 3760 ASSERT_TRUE(tag_alpha.Get(SINGLETON_TAG) == PSTR("alpha")); | 3758 ASSERT_TRUE(tag_alpha.Get(SINGLETON_TAG) == "alpha"); |
| 3761 ASSERT_TRUE(tag_alpha.Get(NON_UNIQUE_NAME) == PSTR("update1")); | 3759 ASSERT_TRUE(tag_alpha.Get(NON_UNIQUE_NAME) == "update1"); |
| 3762 Entry tag_bob(&trans, GET_BY_TAG, PSTR("bob")); | 3760 Entry tag_bob(&trans, GET_BY_TAG, "bob"); |
| 3763 ASSERT_TRUE(tag_bob.good()); | 3761 ASSERT_TRUE(tag_bob.good()); |
| 3764 ASSERT_TRUE(!tag_bob.Get(IS_DEL)); | 3762 ASSERT_TRUE(!tag_bob.Get(IS_DEL)); |
| 3765 ASSERT_TRUE(tag_bob.Get(SINGLETON_TAG) == PSTR("bob")); | 3763 ASSERT_TRUE(tag_bob.Get(SINGLETON_TAG) == "bob"); |
| 3766 ASSERT_TRUE(tag_bob.Get(NON_UNIQUE_NAME) == PSTR("update2")); | 3764 ASSERT_TRUE(tag_bob.Get(NON_UNIQUE_NAME) == "update2"); |
| 3767 // The old item should be unchanged. | 3765 // The old item should be unchanged. |
| 3768 Entry hurdle(&trans, GET_BY_HANDLE, hurdle_handle); | 3766 Entry hurdle(&trans, GET_BY_HANDLE, hurdle_handle); |
| 3769 ASSERT_TRUE(hurdle.good()); | 3767 ASSERT_TRUE(hurdle.good()); |
| 3770 ASSERT_TRUE(!hurdle.Get(IS_DEL)); | 3768 ASSERT_TRUE(!hurdle.Get(IS_DEL)); |
| 3771 ASSERT_TRUE(hurdle.Get(SINGLETON_TAG).empty()); | 3769 ASSERT_TRUE(hurdle.Get(SINGLETON_TAG).empty()); |
| 3772 ASSERT_TRUE(hurdle.Get(NON_UNIQUE_NAME) == PSTR("bob")); | 3770 ASSERT_TRUE(hurdle.Get(NON_UNIQUE_NAME) == "bob"); |
| 3773 } | 3771 } |
| 3774 } | 3772 } |
| 3775 | 3773 |
| 3776 class SyncerPositionUpdateTest : public SyncerTest { | 3774 class SyncerPositionUpdateTest : public SyncerTest { |
| 3777 public: | 3775 public: |
| 3778 SyncerPositionUpdateTest() : next_update_id_(1), next_revision_(1) {} | 3776 SyncerPositionUpdateTest() : next_update_id_(1), next_revision_(1) {} |
| 3779 | 3777 |
| 3780 protected: | 3778 protected: |
| 3781 void ExpectLocalItemsInServerOrder() { | 3779 void ExpectLocalItemsInServerOrder() { |
| 3782 if (position_map_.empty()) | 3780 if (position_map_.empty()) |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3986 Add(low_id_); | 3984 Add(low_id_); |
| 3987 Add(high_id_); | 3985 Add(high_id_); |
| 3988 syncer_->SyncShare(this); | 3986 syncer_->SyncShare(this); |
| 3989 ExpectLocalOrderIsByServerId(); | 3987 ExpectLocalOrderIsByServerId(); |
| 3990 } | 3988 } |
| 3991 | 3989 |
| 3992 const SyncerTest::CommitOrderingTest | 3990 const SyncerTest::CommitOrderingTest |
| 3993 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; | 3991 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; |
| 3994 | 3992 |
| 3995 } // namespace browser_sync | 3993 } // namespace browser_sync |
| OLD | NEW |