| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Syncer unit tests. Unfortunately a lot of these tests | 5 // Syncer unit tests. Unfortunately a lot of these tests |
| 6 // are outdated and need to be reworked and updated. | 6 // are outdated and need to be reworked and updated. |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <list> | 10 #include <list> |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 ASSERT_TRUE(expected_positions.size() == | 388 ASSERT_TRUE(expected_positions.size() == |
| 389 mock_server_->committed_ids().size()); | 389 mock_server_->committed_ids().size()); |
| 390 // If this test starts failing, be aware other sort orders could be valid. | 390 // If this test starts failing, be aware other sort orders could be valid. |
| 391 for (size_t i = 0; i < expected_positions.size(); ++i) { | 391 for (size_t i = 0; i < expected_positions.size(); ++i) { |
| 392 SCOPED_TRACE(i); | 392 SCOPED_TRACE(i); |
| 393 EXPECT_EQ(1u, expected_positions.count(i)); | 393 EXPECT_EQ(1u, expected_positions.count(i)); |
| 394 EXPECT_EQ(expected_positions[i], mock_server_->committed_ids()[i]); | 394 EXPECT_EQ(expected_positions[i], mock_server_->committed_ids()[i]); |
| 395 } | 395 } |
| 396 } | 396 } |
| 397 | 397 |
| 398 void DoTruncationTest(const vector<int64>& unsynced_handle_view, | |
| 399 const vector<int64>& expected_handle_order) { | |
| 400 for (size_t limit = expected_handle_order.size() + 2; limit > 0; --limit) { | |
| 401 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | |
| 402 | |
| 403 ModelSafeRoutingInfo routes; | |
| 404 GetModelSafeRoutingInfo(&routes); | |
| 405 ModelTypeSet types = GetRoutingInfoTypes(routes); | |
| 406 sessions::OrderedCommitSet output_set; | |
| 407 GetCommitIds(&wtrans, types, limit, &output_set); | |
| 408 size_t truncated_size = std::min(limit, expected_handle_order.size()); | |
| 409 ASSERT_EQ(truncated_size, output_set.Size()); | |
| 410 for (size_t i = 0; i < truncated_size; ++i) { | |
| 411 ASSERT_EQ(expected_handle_order[i], output_set.GetCommitHandleAt(i)) | |
| 412 << "At index " << i << " with batch size limited to " << limit; | |
| 413 } | |
| 414 ASSERT_EQ(truncated_size, output_set.Size()); | |
| 415 for (size_t i = 0; i < truncated_size; ++i) { | |
| 416 SCOPED_TRACE(::testing::Message("Projection mismatch with i = ") << i); | |
| 417 int64 handle = output_set.GetCommitHandleAt(i); | |
| 418 ASSERT_EQ(expected_handle_order[i], handle); | |
| 419 } | |
| 420 } | |
| 421 } | |
| 422 | |
| 423 const StatusController& status() { | 398 const StatusController& status() { |
| 424 return session_->status_controller(); | 399 return session_->status_controller(); |
| 425 } | 400 } |
| 426 | 401 |
| 427 Directory* directory() { | 402 Directory* directory() { |
| 428 return dir_maker_.directory(); | 403 return dir_maker_.directory(); |
| 429 } | 404 } |
| 430 | 405 |
| 431 const std::string local_cache_guid() { | 406 const std::string local_cache_guid() { |
| 432 return directory()->cache_guid(); | 407 return directory()->cache_guid(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 syncable::ReadTransaction trans(FROM_HERE, directory()); | 504 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 530 GetUnsyncedEntries(&trans, &handles); | 505 GetUnsyncedEntries(&trans, &handles); |
| 531 } | 506 } |
| 532 ASSERT_EQ(0u, handles.size()); | 507 ASSERT_EQ(0u, handles.size()); |
| 533 } | 508 } |
| 534 // TODO(sync): When we can dynamically connect and disconnect the mock | 509 // TODO(sync): When we can dynamically connect and disconnect the mock |
| 535 // ServerConnectionManager test disconnected GetUnsyncedEntries here. It's a | 510 // ServerConnectionManager test disconnected GetUnsyncedEntries here. It's a |
| 536 // regression for a very old bug. | 511 // regression for a very old bug. |
| 537 } | 512 } |
| 538 | 513 |
| 539 TEST_F(SyncerTest, GetCommitIdsCommandTruncates) { | |
| 540 syncable::Id root = ids_.root(); | |
| 541 // Create two server entries. | |
| 542 mock_server_->AddUpdateDirectory(ids_.MakeServer("x"), root, "X", 10, 10, | |
| 543 foreign_cache_guid(), "-1"); | |
| 544 mock_server_->AddUpdateDirectory(ids_.MakeServer("w"), root, "W", 10, 10, | |
| 545 foreign_cache_guid(), "-2"); | |
| 546 SyncShareNudge(); | |
| 547 | |
| 548 // Create some new client entries. | |
| 549 CreateUnsyncedDirectory("C", ids_.MakeLocal("c")); | |
| 550 CreateUnsyncedDirectory("B", ids_.MakeLocal("b")); | |
| 551 CreateUnsyncedDirectory("D", ids_.MakeLocal("d")); | |
| 552 CreateUnsyncedDirectory("E", ids_.MakeLocal("e")); | |
| 553 CreateUnsyncedDirectory("J", ids_.MakeLocal("j")); | |
| 554 | |
| 555 vector<int64> expected_order; | |
| 556 { | |
| 557 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | |
| 558 MutableEntry entry_x(&wtrans, GET_BY_ID, ids_.MakeServer("x")); | |
| 559 MutableEntry entry_b(&wtrans, GET_BY_ID, ids_.MakeLocal("b")); | |
| 560 MutableEntry entry_c(&wtrans, GET_BY_ID, ids_.MakeLocal("c")); | |
| 561 MutableEntry entry_d(&wtrans, GET_BY_ID, ids_.MakeLocal("d")); | |
| 562 MutableEntry entry_e(&wtrans, GET_BY_ID, ids_.MakeLocal("e")); | |
| 563 MutableEntry entry_w(&wtrans, GET_BY_ID, ids_.MakeServer("w")); | |
| 564 MutableEntry entry_j(&wtrans, GET_BY_ID, ids_.MakeLocal("j")); | |
| 565 entry_x.PutIsUnsynced(true); | |
| 566 entry_b.PutParentId(entry_x.GetId()); | |
| 567 entry_d.PutParentId(entry_b.GetId()); | |
| 568 entry_c.PutParentId(entry_x.GetId()); | |
| 569 entry_c.PutPredecessor(entry_b.GetId()); | |
| 570 entry_e.PutParentId(entry_c.GetId()); | |
| 571 entry_w.PutPredecessor(entry_x.GetId()); | |
| 572 entry_w.PutIsUnsynced(true); | |
| 573 entry_w.PutServerVersion(20); | |
| 574 entry_w.PutIsUnappliedUpdate(true); // Fake a conflict. | |
| 575 entry_j.PutPredecessor(entry_w.GetId()); | |
| 576 | |
| 577 // The expected order is "x", "b", "c", "d", "e", "j", truncated | |
| 578 // appropriately. | |
| 579 expected_order.push_back(entry_x.GetMetahandle()); | |
| 580 expected_order.push_back(entry_b.GetMetahandle()); | |
| 581 expected_order.push_back(entry_c.GetMetahandle()); | |
| 582 expected_order.push_back(entry_d.GetMetahandle()); | |
| 583 expected_order.push_back(entry_e.GetMetahandle()); | |
| 584 expected_order.push_back(entry_j.GetMetahandle()); | |
| 585 } | |
| 586 | |
| 587 // The arrangement is now: x (b (d) c (e)) w j | |
| 588 // Entry "w" is in conflict, so it is not eligible for commit. | |
| 589 vector<int64> unsynced_handle_view; | |
| 590 { | |
| 591 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | |
| 592 GetUnsyncedEntries(&rtrans, &unsynced_handle_view); | |
| 593 } | |
| 594 DoTruncationTest(unsynced_handle_view, expected_order); | |
| 595 } | |
| 596 | |
| 597 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) { | 514 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) { |
| 598 const ModelTypeSet throttled_types(BOOKMARKS); | 515 const ModelTypeSet throttled_types(BOOKMARKS); |
| 599 sync_pb::EntitySpecifics bookmark_data; | 516 sync_pb::EntitySpecifics bookmark_data; |
| 600 AddDefaultFieldValue(BOOKMARKS, &bookmark_data); | 517 AddDefaultFieldValue(BOOKMARKS, &bookmark_data); |
| 601 | 518 |
| 602 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, | 519 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, |
| 603 foreign_cache_guid(), "-1"); | 520 foreign_cache_guid(), "-1"); |
| 604 SyncShareNudge(); | 521 SyncShareNudge(); |
| 605 | 522 |
| 606 { | 523 { |
| (...skipping 4137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4744 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); | 4661 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
| 4745 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 4662 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
| 4746 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 4663 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
| 4747 } else { | 4664 } else { |
| 4748 EXPECT_TRUE(final_monitor_records.empty()) | 4665 EXPECT_TRUE(final_monitor_records.empty()) |
| 4749 << "Should not restore records after successful bookmark commit."; | 4666 << "Should not restore records after successful bookmark commit."; |
| 4750 } | 4667 } |
| 4751 } | 4668 } |
| 4752 | 4669 |
| 4753 } // namespace syncer | 4670 } // namespace syncer |
| OLD | NEW |