| 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..b56f9a168047fcd23f1bf7e57d1b4968d5644ebc 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
|
| @@ -5,6 +5,8 @@
|
| #include <string>
|
| #include <vector>
|
|
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/memory/scoped_vector.h"
|
| #include "chrome/browser/sync_file_system/local_sync_operation_resolver.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "webkit/fileapi/syncable/file_change.h"
|
| @@ -15,15 +17,24 @@ namespace sync_file_system {
|
| namespace {
|
|
|
| struct Input {
|
| - bool has_remote_change;
|
| - FileChange remote_file_change;
|
| + scoped_ptr<FileChange> remote_file_change;
|
| + SyncFileType remote_file_type_in_metadata;
|
|
|
| - std::string DebugString() {
|
| + std::string DebugString() const {
|
| + std::string change_type =
|
| + (remote_file_change == NULL) ? "none"
|
| + : remote_file_change->DebugString();
|
| std::ostringstream ss;
|
| - ss << "has_remote_change: " << (has_remote_change ? "true" : "false")
|
| - << ", RemoteFileChange: " << remote_file_change.DebugString();
|
| + ss << "RemoteFileChange: " << change_type
|
| + << ", RemoteFileTypeInMetadata: " << remote_file_type_in_metadata;
|
| return ss.str();
|
| }
|
| +
|
| + Input(FileChange* remote_file_change,
|
| + SyncFileType remote_file_type_in_metadata)
|
| + : remote_file_change(remote_file_change),
|
| + remote_file_type_in_metadata(remote_file_type_in_metadata) {
|
| + }
|
| };
|
|
|
| template <typename type, size_t array_size>
|
| @@ -31,24 +42,40 @@ 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);
|
| +ScopedVector<Input> CreateInput() {
|
| + SyncFileType dummy_file_type = SYNC_FILE_TYPE_UNKNOWN;
|
| +
|
| + ScopedVector<Input> vector;
|
| + vector.push_back(new Input(NULL, SYNC_FILE_TYPE_UNKNOWN));
|
| + vector.push_back(new Input(NULL, SYNC_FILE_TYPE_FILE));
|
| + vector.push_back(new Input(NULL, SYNC_FILE_TYPE_DIRECTORY));
|
| +
|
| + // When remote_file_change exists, the resolver does not take care of
|
| + // remote_file_type_in_metadata.
|
| + vector.push_back(new Input(
|
| + new FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
|
| + SYNC_FILE_TYPE_FILE),
|
| + dummy_file_type));
|
| + vector.push_back(new Input(
|
| + new FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
|
| + SYNC_FILE_TYPE_DIRECTORY),
|
| + dummy_file_type));
|
| + vector.push_back(new Input(
|
| + new FileChange(FileChange::FILE_CHANGE_DELETE,
|
| + SYNC_FILE_TYPE_FILE),
|
| + dummy_file_type));
|
| + vector.push_back(new Input(
|
| + new FileChange(FileChange::FILE_CHANGE_DELETE,
|
| + SYNC_FILE_TYPE_DIRECTORY),
|
| + dummy_file_type));
|
| +
|
| + return vector.Pass();
|
| }
|
|
|
| -std::vector<Input> CreateInput() {
|
| - const Input inputs[] = {
|
| - { false, CreateDummyFileChange() },
|
| - { true, FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
|
| - SYNC_FILE_TYPE_FILE) },
|
| - { true, FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
|
| - SYNC_FILE_TYPE_DIRECTORY) },
|
| - { true, FileChange(FileChange::FILE_CHANGE_DELETE,
|
| - SYNC_FILE_TYPE_FILE) },
|
| - { true, FileChange(FileChange::FILE_CHANGE_DELETE,
|
| - SYNC_FILE_TYPE_DIRECTORY) },
|
| - };
|
| - return CreateList(inputs);
|
| +std::string DebugString(const ScopedVector<Input>& inputs, int number) {
|
| + std::ostringstream ss;
|
| + ss << "Case " << number << ": (" << inputs[number]->DebugString() << ")";
|
| + return ss.str();
|
| }
|
|
|
| } // namespace
|
| @@ -67,6 +94,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,
|
| @@ -74,36 +104,40 @@ TEST_F(LocalSyncOperationResolverTest, ResolveForAddOrUpdateFile) {
|
| };
|
|
|
| ExpectedTypes expected_types = CreateList(kExpectedTypes);
|
| - std::vector<Input> inputs = CreateInput();
|
| + ScopedVector<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)
|
| + for (ExpectedTypes::size_type i = 0; i < expected_types.size(); ++i) {
|
| 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]->remote_file_change.get(),
|
| + 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,
|
| };
|
|
|
| ExpectedTypes expected_types = CreateList(kExpectedTypes);
|
| - std::vector<Input> inputs = CreateInput();
|
| + ScopedVector<Input> inputs = CreateInput();
|
|
|
| ASSERT_EQ(expected_types.size(), inputs.size());
|
| - for (ExpectedTypes::size_type i = 0; i < expected_types.size(); ++i)
|
| + 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]->remote_file_change.get()))
|
| + << DebugString(inputs, i);
|
| + }
|
| }
|
|
|
| TEST_F(LocalSyncOperationResolverTest, ResolveForAddDirectory) {
|
| @@ -111,46 +145,37 @@ 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,
|
| };
|
|
|
| ExpectedTypes expected_types = CreateList(kExpectedTypes);
|
| - std::vector<Input> inputs = CreateInput();
|
| + ScopedVector<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)
|
| + 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]->remote_file_change.get(),
|
| + inputs[i]->remote_file_type_in_metadata))
|
| + << DebugString(inputs, i);
|
| + }
|
| }
|
|
|
| TEST_F(LocalSyncOperationResolverTest, ResolveForAddDirectoryInConflict) {
|
| - const LocalSyncOperationType kExpectedTypes[] = {
|
| - 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,
|
| - };
|
| -
|
| - ExpectedTypes expected_types = CreateList(kExpectedTypes);
|
| - std::vector<Input> inputs = CreateInput();
|
| -
|
| - ASSERT_EQ(expected_types.size(), inputs.size());
|
| - 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() << ")";
|
| + EXPECT_EQ(LOCAL_SYNC_OPERATION_RESOLVE_TO_LOCAL,
|
| + Resolver::ResolveForAddDirectoryInConflict());
|
| }
|
|
|
| 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,
|
| @@ -158,16 +183,16 @@ TEST_F(LocalSyncOperationResolverTest, ResolveForDeleteFile) {
|
| };
|
|
|
| ExpectedTypes expected_types = CreateList(kExpectedTypes);
|
| - std::vector<Input> inputs = CreateInput();
|
| + ScopedVector<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)
|
| + 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]->remote_file_change.get(),
|
| + inputs[i]->remote_file_type_in_metadata))
|
| + << DebugString(inputs, i);
|
| + }
|
| }
|
|
|
| TEST_F(LocalSyncOperationResolverTest, ResolveForDeleteFileInConflict) {
|
| @@ -175,41 +200,48 @@ 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,
|
| };
|
|
|
| ExpectedTypes expected_types = CreateList(kExpectedTypes);
|
| - std::vector<Input> inputs = CreateInput();
|
| + ScopedVector<Input> inputs = CreateInput();
|
|
|
| ASSERT_EQ(expected_types.size(), inputs.size());
|
| - for (ExpectedTypes::size_type i = 0; i < expected_types.size(); ++i)
|
| + 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]->remote_file_change.get()))
|
| + << 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,
|
| };
|
|
|
| ExpectedTypes expected_types = CreateList(kExpectedTypes);
|
| - std::vector<Input> inputs = CreateInput();
|
| + ScopedVector<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)
|
| + 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]->remote_file_change.get(),
|
| + inputs[i]->remote_file_type_in_metadata))
|
| + << DebugString(inputs, i);
|
| + }
|
| }
|
|
|
| TEST_F(LocalSyncOperationResolverTest, ResolveForDeleteDirectoryInConflict) {
|
| @@ -217,19 +249,23 @@ 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,
|
| };
|
|
|
| ExpectedTypes expected_types = CreateList(kExpectedTypes);
|
| - std::vector<Input> inputs = CreateInput();
|
| + ScopedVector<Input> inputs = CreateInput();
|
|
|
| ASSERT_EQ(expected_types.size(), inputs.size());
|
| - for (ExpectedTypes::size_type i = 0; i < expected_types.size(); ++i)
|
| + 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]->remote_file_change.get()))
|
| + << DebugString(inputs, i);
|
| + }
|
| }
|
|
|
| } // namespace sync_file_system
|
|
|