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

Side by Side Diff: chrome/browser/sync/engine/syncer_unittest.cc

Issue 8631021: [Sync] Prevent uploading throttled datatypes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For committing. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Syncer unit tests. Unfortunately a lot of these tests 5 // Syncer unit tests. Unfortunately a lot of these tests
6 // are outdated and need to be reworked and updated. 6 // are outdated and need to be reworked and updated.
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <limits> 9 #include <limits>
10 #include <list> 10 #include <list>
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 StatusController* status = session_->mutable_status_controller(); 364 StatusController* status = session_->mutable_status_controller();
365 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); 365 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir);
366 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans); 366 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans);
367 status->set_unsynced_handles(unsynced_handle_view); 367 status->set_unsynced_handles(unsynced_handle_view);
368 368
369 ModelSafeRoutingInfo routes; 369 ModelSafeRoutingInfo routes;
370 GetModelSafeRoutingInfo(&routes); 370 GetModelSafeRoutingInfo(&routes);
371 GetCommitIdsCommand command(limit); 371 GetCommitIdsCommand command(limit);
372 command.BuildCommitIds( 372 command.BuildCommitIds(
373 session_->status_controller().unsynced_handles(), 373 session_->status_controller().unsynced_handles(),
374 session_->write_transaction(), routes); 374 session_->write_transaction(), routes, syncable::ModelTypeSet());
375 vector<syncable::Id> output = 375 vector<syncable::Id> output =
376 command.ordered_commit_set_->GetAllCommitIds(); 376 command.ordered_commit_set_->GetAllCommitIds();
377 size_t truncated_size = std::min(limit, expected_id_order.size()); 377 size_t truncated_size = std::min(limit, expected_id_order.size());
378 ASSERT_TRUE(truncated_size == output.size()); 378 ASSERT_TRUE(truncated_size == output.size());
379 for (size_t i = 0; i < truncated_size; ++i) { 379 for (size_t i = 0; i < truncated_size; ++i) {
380 ASSERT_TRUE(expected_id_order[i] == output[i]) 380 ASSERT_TRUE(expected_id_order[i] == output[i])
381 << "At index " << i << " with batch size limited to " << limit; 381 << "At index " << i << " with batch size limited to " << limit;
382 } 382 }
383 sessions::OrderedCommitSet::Projection proj; 383 sessions::OrderedCommitSet::Projection proj;
384 proj = command.ordered_commit_set_->GetCommitIdProjection(GROUP_PASSIVE); 384 proj = command.ordered_commit_set_->GetCommitIdProjection(GROUP_PASSIVE);
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 vector<syncable::Id> expected_order; 549 vector<syncable::Id> expected_order;
550 // The expected order is "x", "b", "c", "e", truncated appropriately. 550 // The expected order is "x", "b", "c", "e", truncated appropriately.
551 unsynced_handle_view.push_back(handle_e); 551 unsynced_handle_view.push_back(handle_e);
552 expected_order.push_back(ids_.MakeLocal("x")); 552 expected_order.push_back(ids_.MakeLocal("x"));
553 expected_order.push_back(ids_.MakeLocal("b")); 553 expected_order.push_back(ids_.MakeLocal("b"));
554 expected_order.push_back(ids_.MakeLocal("c")); 554 expected_order.push_back(ids_.MakeLocal("c"));
555 expected_order.push_back(ids_.MakeLocal("e")); 555 expected_order.push_back(ids_.MakeLocal("e"));
556 DoTruncationTest(dir, unsynced_handle_view, expected_order); 556 DoTruncationTest(dir, unsynced_handle_view, expected_order);
557 } 557 }
558 558
559 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) {
560 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
561 ASSERT_TRUE(dir.good());
562 syncable::ModelTypeSet throttled_types;
563 throttled_types.insert(syncable::BOOKMARKS);
564 KeyParams key_params = {"localhost", "dummy", "foobar"};
565 sync_pb::EntitySpecifics bookmark_data;
566 AddDefaultExtensionValue(syncable::BOOKMARKS, &bookmark_data);
567
568 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10);
569 SyncShareAsDelegate();
570
571 {
572 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir);
573 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
574 ASSERT_TRUE(A.good());
575 A.Put(IS_UNSYNCED, true);
576 A.Put(SPECIFICS, bookmark_data);
577 A.Put(NON_UNIQUE_NAME, "bookmark");
578 }
579
580 // Now set the throttled types.
581 context_->SetUnthrottleTime(
582 throttled_types,
583 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1200));
584 SyncShareAsDelegate();
585
586 {
587 // Nothing should have been committed as bookmarks is throttled.
588 ReadTransaction rtrans(FROM_HERE, dir);
589 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1));
590 ASSERT_TRUE(entryA.good());
591 EXPECT_TRUE(entryA.Get(IS_UNSYNCED));
592 }
593
594 // Now unthrottle.
595 context_->SetUnthrottleTime(
596 throttled_types,
597 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(1200));
598 SyncShareAsDelegate();
599 {
600 // It should have been committed.
601 ReadTransaction rtrans(FROM_HERE, dir);
602 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1));
603 ASSERT_TRUE(entryA.good());
604 EXPECT_FALSE(entryA.Get(IS_UNSYNCED));
605 }
606 }
607
559 TEST_F(SyncerTest, GetCommitIdsFiltersUnreadyEntries) { 608 TEST_F(SyncerTest, GetCommitIdsFiltersUnreadyEntries) {
560 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); 609 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name());
561 ASSERT_TRUE(dir.good()); 610 ASSERT_TRUE(dir.good());
562 KeyParams key_params = {"localhost", "dummy", "foobar"}; 611 KeyParams key_params = {"localhost", "dummy", "foobar"};
563 sync_pb::EncryptedData encrypted; 612 sync_pb::EncryptedData encrypted;
564 sync_pb::EntitySpecifics encrypted_bookmark; 613 sync_pb::EntitySpecifics encrypted_bookmark;
565 encrypted_bookmark.mutable_encrypted(); 614 encrypted_bookmark.mutable_encrypted();
566 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark); 615 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark);
567 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); 616 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10);
568 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); 617 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10);
(...skipping 4737 matching lines...) Expand 10 before | Expand all | Expand 10 after
5306 Add(low_id_); 5355 Add(low_id_);
5307 Add(high_id_); 5356 Add(high_id_);
5308 SyncShareAsDelegate(); 5357 SyncShareAsDelegate();
5309 ExpectLocalOrderIsByServerId(); 5358 ExpectLocalOrderIsByServerId();
5310 } 5359 }
5311 5360
5312 const SyncerTest::CommitOrderingTest 5361 const SyncerTest::CommitOrderingTest
5313 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; 5362 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()};
5314 5363
5315 } // namespace browser_sync 5364 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/syncer.cc ('k') | chrome/browser/sync/sessions/sync_session_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698