OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Syncer unit tests. Unfortunately a lot of these tests | 5 // Syncer unit tests. Unfortunately a lot of these tests |
6 // are outdated and need to be reworked and updated. | 6 // are outdated and need to be reworked and updated. |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <limits> | 9 #include <limits> |
10 #include <list> | 10 #include <list> |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 for (size_t limit = expected_id_order.size() + 2; limit > 0; --limit) { | 362 for (size_t limit = expected_id_order.size() + 2; limit > 0; --limit) { |
363 StatusController* status = session_->status_controller(); | 363 StatusController* status = session_->status_controller(); |
364 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | 364 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); |
365 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans); | 365 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans); |
366 status->set_unsynced_handles(unsynced_handle_view); | 366 status->set_unsynced_handles(unsynced_handle_view); |
367 | 367 |
368 ModelSafeRoutingInfo routes; | 368 ModelSafeRoutingInfo routes; |
369 GetModelSafeRoutingInfo(&routes); | 369 GetModelSafeRoutingInfo(&routes); |
370 GetCommitIdsCommand command(limit); | 370 GetCommitIdsCommand command(limit); |
371 command.BuildCommitIds(session_->status_controller()->unsynced_handles(), | 371 command.BuildCommitIds(session_->status_controller()->unsynced_handles(), |
372 session_->write_transaction(), routes); | 372 session_->write_transaction(), routes, syncable::ModelTypeSet()); |
373 vector<syncable::Id> output = | 373 vector<syncable::Id> output = |
374 command.ordered_commit_set_->GetAllCommitIds(); | 374 command.ordered_commit_set_->GetAllCommitIds(); |
375 size_t truncated_size = std::min(limit, expected_id_order.size()); | 375 size_t truncated_size = std::min(limit, expected_id_order.size()); |
376 ASSERT_TRUE(truncated_size == output.size()); | 376 ASSERT_TRUE(truncated_size == output.size()); |
377 for (size_t i = 0; i < truncated_size; ++i) { | 377 for (size_t i = 0; i < truncated_size; ++i) { |
378 ASSERT_TRUE(expected_id_order[i] == output[i]) | 378 ASSERT_TRUE(expected_id_order[i] == output[i]) |
379 << "At index " << i << " with batch size limited to " << limit; | 379 << "At index " << i << " with batch size limited to " << limit; |
380 } | 380 } |
381 sessions::OrderedCommitSet::Projection proj; | 381 sessions::OrderedCommitSet::Projection proj; |
382 proj = command.ordered_commit_set_->GetCommitIdProjection(GROUP_PASSIVE); | 382 proj = command.ordered_commit_set_->GetCommitIdProjection(GROUP_PASSIVE); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 vector<syncable::Id> expected_order; | 547 vector<syncable::Id> expected_order; |
548 // The expected order is "x", "b", "c", "e", truncated appropriately. | 548 // The expected order is "x", "b", "c", "e", truncated appropriately. |
549 unsynced_handle_view.push_back(handle_e); | 549 unsynced_handle_view.push_back(handle_e); |
550 expected_order.push_back(ids_.MakeLocal("x")); | 550 expected_order.push_back(ids_.MakeLocal("x")); |
551 expected_order.push_back(ids_.MakeLocal("b")); | 551 expected_order.push_back(ids_.MakeLocal("b")); |
552 expected_order.push_back(ids_.MakeLocal("c")); | 552 expected_order.push_back(ids_.MakeLocal("c")); |
553 expected_order.push_back(ids_.MakeLocal("e")); | 553 expected_order.push_back(ids_.MakeLocal("e")); |
554 DoTruncationTest(dir, unsynced_handle_view, expected_order); | 554 DoTruncationTest(dir, unsynced_handle_view, expected_order); |
555 } | 555 } |
556 | 556 |
| 557 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) { |
| 558 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 559 ASSERT_TRUE(dir.good()); |
| 560 syncable::ModelTypeSet throttled_types; |
| 561 throttled_types.insert(syncable::BOOKMARKS); |
| 562 KeyParams key_params = {"localhost", "dummy", "foobar"}; |
| 563 sync_pb::EntitySpecifics bookmark_data; |
| 564 AddDefaultExtensionValue(syncable::BOOKMARKS, &bookmark_data); |
| 565 |
| 566 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); |
| 567 SyncShareAsDelegate(); |
| 568 |
| 569 { |
| 570 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); |
| 571 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
| 572 ASSERT_TRUE(A.good()); |
| 573 A.Put(IS_UNSYNCED, true); |
| 574 A.Put(SPECIFICS, bookmark_data); |
| 575 A.Put(NON_UNIQUE_NAME, "bookmark"); |
| 576 } |
| 577 |
| 578 // Now set the throttled types. |
| 579 context_->SetUnthrottleTime(throttled_types, |
| 580 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1200)); |
| 581 SyncShareAsDelegate(); |
| 582 |
| 583 { |
| 584 // Nothing should have been committed as bookmarks is throttled. |
| 585 ReadTransaction rtrans(FROM_HERE, dir); |
| 586 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); |
| 587 ASSERT_TRUE(entryA.good()); |
| 588 EXPECT_TRUE(entryA.Get(IS_UNSYNCED)); |
| 589 } |
| 590 |
| 591 // Now unthrottle. |
| 592 context_->SetUnthrottleTime(throttled_types, |
| 593 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(1200)); |
| 594 SyncShareAsDelegate(); |
| 595 { |
| 596 // It should have been committed. |
| 597 ReadTransaction rtrans(FROM_HERE, dir); |
| 598 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); |
| 599 ASSERT_TRUE(entryA.good()); |
| 600 EXPECT_FALSE(entryA.Get(IS_UNSYNCED)); |
| 601 } |
| 602 } |
| 603 |
557 TEST_F(SyncerTest, GetCommitIdsFiltersUnreadyEntries) { | 604 TEST_F(SyncerTest, GetCommitIdsFiltersUnreadyEntries) { |
558 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 605 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
559 ASSERT_TRUE(dir.good()); | 606 ASSERT_TRUE(dir.good()); |
560 KeyParams key_params = {"localhost", "dummy", "foobar"}; | 607 KeyParams key_params = {"localhost", "dummy", "foobar"}; |
561 sync_pb::EncryptedData encrypted; | 608 sync_pb::EncryptedData encrypted; |
562 sync_pb::EntitySpecifics encrypted_bookmark; | 609 sync_pb::EntitySpecifics encrypted_bookmark; |
563 encrypted_bookmark.mutable_encrypted(); | 610 encrypted_bookmark.mutable_encrypted(); |
564 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark); | 611 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark); |
565 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); | 612 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); |
566 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); | 613 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); |
(...skipping 4734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5301 Add(low_id_); | 5348 Add(low_id_); |
5302 Add(high_id_); | 5349 Add(high_id_); |
5303 SyncShareAsDelegate(); | 5350 SyncShareAsDelegate(); |
5304 ExpectLocalOrderIsByServerId(); | 5351 ExpectLocalOrderIsByServerId(); |
5305 } | 5352 } |
5306 | 5353 |
5307 const SyncerTest::CommitOrderingTest | 5354 const SyncerTest::CommitOrderingTest |
5308 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; | 5355 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; |
5309 | 5356 |
5310 } // namespace browser_sync | 5357 } // namespace browser_sync |
OLD | NEW |