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

Unified Diff: components/sync/model_impl/shared_model_type_processor_unittest.cc

Issue 2916133002: [Sync] Support commit only types. (Closed)
Patch Set: Added more checks to syncer unittest. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/sync/model_impl/shared_model_type_processor_unittest.cc
diff --git a/components/sync/model_impl/shared_model_type_processor_unittest.cc b/components/sync/model_impl/shared_model_type_processor_unittest.cc
index 091d78e9fa229da9ff035a004d4aa039bfef7df4..e19ae42b289d44ecf6e91ba279ede058f4a8fa15 100644
--- a/components/sync/model_impl/shared_model_type_processor_unittest.cc
+++ b/components/sync/model_impl/shared_model_type_processor_unittest.cc
@@ -75,15 +75,20 @@ bool IsInvalidStorageKey(const std::string& storage_key) {
return 0 == storage_key.find(InvalidStorageKeyPrefix);
}
+std::unique_ptr<ModelTypeChangeProcessor>
+CreateProcessor(bool commit_only, ModelType type, ModelTypeSyncBridge* bridge) {
+ return base::MakeUnique<SharedModelTypeProcessor>(
+ type, bridge, base::RepeatingClosure(), commit_only);
+}
+
class TestModelTypeSyncBridge : public FakeModelTypeSyncBridge {
public:
- TestModelTypeSyncBridge()
- : FakeModelTypeSyncBridge(base::Bind(&ModelTypeChangeProcessor::Create,
- base::RepeatingClosure())) {}
+ explicit TestModelTypeSyncBridge(bool commit_only)
+ : FakeModelTypeSyncBridge(base::Bind(&CreateProcessor, commit_only)) {}
- explicit TestModelTypeSyncBridge(
- std::unique_ptr<TestModelTypeSyncBridge> other)
- : TestModelTypeSyncBridge() {
+ TestModelTypeSyncBridge(std::unique_ptr<TestModelTypeSyncBridge> other,
+ bool commit_only)
+ : TestModelTypeSyncBridge(commit_only) {
std::swap(db_, other->db_);
}
@@ -231,7 +236,7 @@ class TestModelTypeSyncBridge : public FakeModelTypeSyncBridge {
class SharedModelTypeProcessorTest : public ::testing::Test {
public:
SharedModelTypeProcessorTest()
- : bridge_(base::MakeUnique<TestModelTypeSyncBridge>()) {}
+ : bridge_(base::MakeUnique<TestModelTypeSyncBridge>(false)) {}
~SharedModelTypeProcessorTest() override { CheckPostConditions(); }
@@ -277,10 +282,10 @@ class SharedModelTypeProcessorTest : public ::testing::Test {
return specifics;
}
- void ResetState(bool keep_db) {
- bridge_ =
- keep_db ? base::MakeUnique<TestModelTypeSyncBridge>(std::move(bridge_))
- : base::MakeUnique<TestModelTypeSyncBridge>();
+ void ResetState(bool keep_db, bool commit_only = false) {
+ bridge_ = keep_db ? base::MakeUnique<TestModelTypeSyncBridge>(
+ std::move(bridge_), commit_only)
+ : base::MakeUnique<TestModelTypeSyncBridge>(commit_only);
worker_ = nullptr;
CheckPostConditions();
}
@@ -748,6 +753,48 @@ TEST_F(SharedModelTypeProcessorTest, LocalCreateItem) {
EXPECT_EQ(1, acked_metadata.server_version());
}
+// Test that commit only types are deleted after commit response.
+TEST_F(SharedModelTypeProcessorTest, CommitOnlySimple) {
+ ResetState(false, true);
+ InitializeToReadyState();
+
+ bridge()->WriteItem(kKey1, kValue1);
+ EXPECT_EQ(1U, db().data_count());
+ EXPECT_EQ(1U, db().metadata_count());
+
+ worker()->ExpectPendingCommits({kHash1});
+ worker()->AckOnePendingCommit();
+ EXPECT_EQ(0U, db().data_count());
+ EXPECT_EQ(0U, db().metadata_count());
+}
+
+// Test that commit only types maintain tracking of entities while unsynced
+// changes exist.
+TEST_F(SharedModelTypeProcessorTest, CommitOnlyUnsyncedChanges) {
+ ResetState(false, true);
+ InitializeToReadyState();
+
+ bridge()->WriteItem(kKey1, kValue1);
+ worker()->ExpectPendingCommits({kHash1});
+ EXPECT_EQ(1U, db().data_count());
+ EXPECT_EQ(1U, db().metadata_count());
+
+ bridge()->WriteItem(kKey1, kValue2);
+ worker()->ExpectPendingCommits({kHash1, kHash1});
+ EXPECT_EQ(1U, db().data_count());
+ EXPECT_EQ(1U, db().metadata_count());
+
+ worker()->AckOnePendingCommit();
+ worker()->ExpectPendingCommits({kHash1});
+ EXPECT_EQ(1U, db().data_count());
+ EXPECT_EQ(1U, db().metadata_count());
+
+ worker()->AckOnePendingCommit();
+ worker()->ExpectPendingCommits(std::vector<std::string>());
Patrick Noland 2017/06/01 21:34:40 weird, does {} not work for this?
skym 2017/06/01 22:43:20 ../../components/sync/model_impl/shared_model_type
+ EXPECT_EQ(0U, db().data_count());
+ EXPECT_EQ(0U, db().metadata_count());
+}
+
// Test that an error applying metadata changes from a commit response is
// propagated to the error handler.
TEST_F(SharedModelTypeProcessorTest, ErrorApplyingAck) {

Powered by Google App Engine
This is Rietveld 408576698