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

Unified Diff: chrome/browser/sync_file_system/local_sync_operation_resolver_unittest.cc

Issue 14851005: SyncFS: Fix LocalSyncOperationResolverTest to cover all test cases (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync_file_system/local_sync_operation_resolver_unittest.cc
diff --git a/chrome/browser/sync_file_system/local_sync_operation_resolver_unittest.cc b/chrome/browser/sync_file_system/local_sync_operation_resolver_unittest.cc
index 202c8a1673c3ef8da7e34384bd5f3792045ccb57..0f8edf1ffd2726665b3eef552e5f8273fcedced1 100644
--- a/chrome/browser/sync_file_system/local_sync_operation_resolver_unittest.cc
+++ b/chrome/browser/sync_file_system/local_sync_operation_resolver_unittest.cc
@@ -17,11 +17,13 @@ namespace {
struct Input {
bool has_remote_change;
FileChange remote_file_change;
kinuko 2013/05/07 04:26:10 Maybe this could be scoped_ptr<FileChange> remote_
nhiroki 2013/05/07 11:13:17 Done.
+ SyncFileType remote_file_type_in_metadata;
- std::string DebugString() {
+ std::string DebugString() const {
std::ostringstream ss;
ss << "has_remote_change: " << (has_remote_change ? "true" : "false")
- << ", RemoteFileChange: " << remote_file_change.DebugString();
+ << ", RemoteFileChange: " << remote_file_change.DebugString()
+ << ", RemoteFileTypeInMetadata: " << remote_file_type_in_metadata;
return ss.str();
}
};
@@ -31,26 +33,38 @@ std::vector<type> CreateList(const type (&inputs)[array_size]) {
return std::vector<type>(inputs, inputs + array_size);
}
-FileChange CreateDummyFileChange() {
- return FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
- SYNC_FILE_TYPE_UNKNOWN);
-}
-
std::vector<Input> CreateInput() {
+ FileChange dummy_change(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
+ SYNC_FILE_TYPE_UNKNOWN);
+ SyncFileType dummy_file_type = SYNC_FILE_TYPE_UNKNOWN;
+
const Input inputs[] = {
- { false, CreateDummyFileChange() },
+ // When has_remote_change==false, the resolver does not take care of
+ // remote_file_change.
+ { false, dummy_change, SYNC_FILE_TYPE_UNKNOWN },
+ { false, dummy_change, SYNC_FILE_TYPE_FILE },
+ { false, dummy_change, SYNC_FILE_TYPE_DIRECTORY },
+
+ // When has_remote_change==true, the resolver does not take care of
+ // remote_file_type_in_metadata.
{ true, FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
- SYNC_FILE_TYPE_FILE) },
+ SYNC_FILE_TYPE_FILE), dummy_file_type },
{ true, FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
- SYNC_FILE_TYPE_DIRECTORY) },
+ SYNC_FILE_TYPE_DIRECTORY), dummy_file_type },
{ true, FileChange(FileChange::FILE_CHANGE_DELETE,
- SYNC_FILE_TYPE_FILE) },
+ SYNC_FILE_TYPE_FILE), dummy_file_type },
{ true, FileChange(FileChange::FILE_CHANGE_DELETE,
- SYNC_FILE_TYPE_DIRECTORY) },
+ SYNC_FILE_TYPE_DIRECTORY), dummy_file_type },
};
return CreateList(inputs);
}
+std::string DebugString(const std::vector<Input>& inputs, int number) {
+ std::ostringstream ss;
+ ss << "Case " << number << ": (" << inputs[number].DebugString() << ")";
+ return ss.str();
+}
+
} // namespace
class LocalSyncOperationResolverTest : public testing::Test {
@@ -67,6 +81,9 @@ class LocalSyncOperationResolverTest : public testing::Test {
TEST_F(LocalSyncOperationResolverTest, ResolveForAddOrUpdateFile) {
const LocalSyncOperationType kExpectedTypes[] = {
LOCAL_SYNC_OPERATION_ADD_FILE,
+ LOCAL_SYNC_OPERATION_UPDATE_FILE,
+ LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE,
+
LOCAL_SYNC_OPERATION_CONFLICT,
LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE,
LOCAL_SYNC_OPERATION_RESOLVE_TO_LOCAL,
@@ -77,19 +94,22 @@ TEST_F(LocalSyncOperationResolverTest, ResolveForAddOrUpdateFile) {
std::vector<Input> inputs = CreateInput();
ASSERT_EQ(expected_types.size(), inputs.size());
- // TODO(nhiroki): Fix inputs so that these tests can cover all cases.
for (ExpectedTypes::size_type i = 0; i < expected_types.size(); ++i)
kinuko 2013/05/07 04:26:10 nit: please put { } for multi-line body (here and
nhiroki 2013/05/07 11:13:17 Done.
EXPECT_EQ(expected_types[i],
Resolver::ResolveForAddOrUpdateFile(
- inputs[i].has_remote_change, inputs[i].remote_file_change,
- SYNC_FILE_TYPE_UNKNOWN))
- << "Case " << i << ": (" << inputs[i].DebugString() << ")";
+ inputs[i].has_remote_change,
+ inputs[i].remote_file_change,
+ inputs[i].remote_file_type_in_metadata))
+ << DebugString(inputs, i);
}
TEST_F(LocalSyncOperationResolverTest, ResolveForAddOrUpdateFileInConflict) {
const LocalSyncOperationType kExpectedTypes[] = {
LOCAL_SYNC_OPERATION_CONFLICT,
LOCAL_SYNC_OPERATION_CONFLICT,
+ LOCAL_SYNC_OPERATION_CONFLICT,
+
+ LOCAL_SYNC_OPERATION_CONFLICT,
LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE,
LOCAL_SYNC_OPERATION_RESOLVE_TO_LOCAL,
LOCAL_SYNC_OPERATION_RESOLVE_TO_LOCAL,
@@ -102,8 +122,9 @@ TEST_F(LocalSyncOperationResolverTest, ResolveForAddOrUpdateFileInConflict) {
for (ExpectedTypes::size_type i = 0; i < expected_types.size(); ++i)
EXPECT_EQ(expected_types[i],
Resolver::ResolveForAddOrUpdateFileInConflict(
- inputs[i].has_remote_change, inputs[i].remote_file_change))
- << "Case " << i << ": (" << inputs[i].DebugString() << ")";
+ inputs[i].has_remote_change,
+ inputs[i].remote_file_change))
+ << DebugString(inputs, i);
}
TEST_F(LocalSyncOperationResolverTest, ResolveForAddDirectory) {
@@ -111,6 +132,9 @@ TEST_F(LocalSyncOperationResolverTest, ResolveForAddDirectory) {
LOCAL_SYNC_OPERATION_ADD_DIRECTORY,
LOCAL_SYNC_OPERATION_RESOLVE_TO_LOCAL,
LOCAL_SYNC_OPERATION_NONE,
+
+ LOCAL_SYNC_OPERATION_RESOLVE_TO_LOCAL,
+ LOCAL_SYNC_OPERATION_NONE,
LOCAL_SYNC_OPERATION_ADD_DIRECTORY,
LOCAL_SYNC_OPERATION_RESOLVE_TO_LOCAL,
};
@@ -119,13 +143,13 @@ TEST_F(LocalSyncOperationResolverTest, ResolveForAddDirectory) {
std::vector<Input> inputs = CreateInput();
ASSERT_EQ(expected_types.size(), inputs.size());
- // TODO(nhiroki): Fix inputs so that these tests can cover all cases.
for (ExpectedTypes::size_type i = 0; i < expected_types.size(); ++i)
EXPECT_EQ(expected_types[i],
Resolver::ResolveForAddDirectory(
- inputs[i].has_remote_change, inputs[i].remote_file_change,
- SYNC_FILE_TYPE_UNKNOWN))
- << "Case " << i << ": (" << inputs[i].DebugString() << ")";
+ inputs[i].has_remote_change,
+ inputs[i].remote_file_change,
+ inputs[i].remote_file_type_in_metadata))
+ << DebugString(inputs, i);
}
TEST_F(LocalSyncOperationResolverTest, ResolveForAddDirectoryInConflict) {
@@ -133,6 +157,9 @@ TEST_F(LocalSyncOperationResolverTest, ResolveForAddDirectoryInConflict) {
LOCAL_SYNC_OPERATION_RESOLVE_TO_LOCAL,
LOCAL_SYNC_OPERATION_RESOLVE_TO_LOCAL,
LOCAL_SYNC_OPERATION_RESOLVE_TO_LOCAL,
+
+ LOCAL_SYNC_OPERATION_RESOLVE_TO_LOCAL,
+ LOCAL_SYNC_OPERATION_RESOLVE_TO_LOCAL,
LOCAL_SYNC_OPERATION_RESOLVE_TO_LOCAL,
LOCAL_SYNC_OPERATION_RESOLVE_TO_LOCAL,
};
@@ -144,13 +171,17 @@ TEST_F(LocalSyncOperationResolverTest, ResolveForAddDirectoryInConflict) {
for (ExpectedTypes::size_type i = 0; i < expected_types.size(); ++i)
EXPECT_EQ(expected_types[i],
Resolver::ResolveForAddDirectoryInConflict(
- inputs[i].has_remote_change, inputs[i].remote_file_change))
- << "Case " << i << ": (" << inputs[i].DebugString() << ")";
+ inputs[i].has_remote_change,
+ inputs[i].remote_file_change))
+ << DebugString(inputs, i);
}
TEST_F(LocalSyncOperationResolverTest, ResolveForDeleteFile) {
const LocalSyncOperationType kExpectedTypes[] = {
LOCAL_SYNC_OPERATION_NONE,
+ LOCAL_SYNC_OPERATION_DELETE_FILE,
+ LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE,
+
LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE,
LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE,
LOCAL_SYNC_OPERATION_DELETE_METADATA,
@@ -161,13 +192,13 @@ TEST_F(LocalSyncOperationResolverTest, ResolveForDeleteFile) {
std::vector<Input> inputs = CreateInput();
ASSERT_EQ(expected_types.size(), inputs.size());
- // TODO(nhiroki): Fix inputs so that these tests can cover all cases.
for (ExpectedTypes::size_type i = 0; i < expected_types.size(); ++i)
EXPECT_EQ(expected_types[i],
Resolver::ResolveForDeleteFile(
- inputs[i].has_remote_change, inputs[i].remote_file_change,
- SYNC_FILE_TYPE_UNKNOWN))
- << "Case " << i << ": (" << inputs[i].DebugString() << ")";
+ inputs[i].has_remote_change,
+ inputs[i].remote_file_change,
+ inputs[i].remote_file_type_in_metadata))
+ << DebugString(inputs, i);
}
TEST_F(LocalSyncOperationResolverTest, ResolveForDeleteFileInConflict) {
@@ -175,6 +206,9 @@ TEST_F(LocalSyncOperationResolverTest, ResolveForDeleteFileInConflict) {
LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE,
LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE,
LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE,
+
+ LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE,
+ LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE,
LOCAL_SYNC_OPERATION_DELETE_METADATA,
LOCAL_SYNC_OPERATION_DELETE_METADATA,
};
@@ -186,14 +220,18 @@ TEST_F(LocalSyncOperationResolverTest, ResolveForDeleteFileInConflict) {
for (ExpectedTypes::size_type i = 0; i < expected_types.size(); ++i)
EXPECT_EQ(expected_types[i],
Resolver::ResolveForDeleteFileInConflict(
- inputs[i].has_remote_change, inputs[i].remote_file_change))
- << "Case " << i << ": (" << inputs[i].DebugString() << ")";
+ inputs[i].has_remote_change,
+ inputs[i].remote_file_change))
+ << DebugString(inputs, i);
}
TEST_F(LocalSyncOperationResolverTest, ResolveForDeleteDirectory) {
const LocalSyncOperationType kExpectedTypes[] = {
LOCAL_SYNC_OPERATION_NONE,
LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE,
+ LOCAL_SYNC_OPERATION_DELETE_DIRECTORY,
+
+ LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE,
LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE,
LOCAL_SYNC_OPERATION_DELETE_METADATA,
LOCAL_SYNC_OPERATION_DELETE_METADATA,
@@ -203,13 +241,13 @@ TEST_F(LocalSyncOperationResolverTest, ResolveForDeleteDirectory) {
std::vector<Input> inputs = CreateInput();
ASSERT_EQ(expected_types.size(), inputs.size());
- // TODO(nhiroki): Fix inputs so that these tests can cover all cases.
for (ExpectedTypes::size_type i = 0; i < expected_types.size(); ++i)
EXPECT_EQ(expected_types[i],
Resolver::ResolveForDeleteDirectory(
- inputs[i].has_remote_change, inputs[i].remote_file_change,
- SYNC_FILE_TYPE_UNKNOWN))
- << "Case " << i << ": (" << inputs[i].DebugString() << ")";
+ inputs[i].has_remote_change,
+ inputs[i].remote_file_change,
+ inputs[i].remote_file_type_in_metadata))
+ << DebugString(inputs, i);
}
TEST_F(LocalSyncOperationResolverTest, ResolveForDeleteDirectoryInConflict) {
@@ -217,6 +255,9 @@ TEST_F(LocalSyncOperationResolverTest, ResolveForDeleteDirectoryInConflict) {
LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE,
LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE,
LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE,
+
+ LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE,
+ LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE,
LOCAL_SYNC_OPERATION_DELETE_METADATA,
LOCAL_SYNC_OPERATION_DELETE_METADATA,
};
@@ -228,8 +269,9 @@ TEST_F(LocalSyncOperationResolverTest, ResolveForDeleteDirectoryInConflict) {
for (ExpectedTypes::size_type i = 0; i < expected_types.size(); ++i)
EXPECT_EQ(expected_types[i],
Resolver::ResolveForDeleteDirectoryInConflict(
- inputs[i].has_remote_change, inputs[i].remote_file_change))
- << "Case " << i << ": (" << inputs[i].DebugString() << ")";
+ inputs[i].has_remote_change,
+ inputs[i].remote_file_change))
+ << DebugString(inputs, i);
}
} // namespace sync_file_system
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698