Chromium Code Reviews| Index: chrome/browser/chromeos/drive/file_system/move_operation_unittest.cc |
| diff --git a/chrome/browser/chromeos/drive/file_system/move_operation_unittest.cc b/chrome/browser/chromeos/drive/file_system/move_operation_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f6df2d6f00c8499601e0a6ae651f59ce0d811a91 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/drive/file_system/move_operation_unittest.cc |
| @@ -0,0 +1,208 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/drive/file_system/move_operation.h" |
| + |
| +#include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
| +#include "chrome/browser/google_apis/test_util.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace drive { |
| +namespace file_system { |
| + |
| +class MoveOperationTest : public OperationTestBase { |
| + protected: |
| + virtual void SetUp() OVERRIDE { |
| + OperationTestBase::SetUp(); |
| + operation_.reset(new MoveOperation(observer(), scheduler(), metadata())); |
| + } |
| + |
| + virtual void TearDown() OVERRIDE { |
| + operation_.reset(); |
| + OperationTestBase::TearDown(); |
| + } |
| + |
| + scoped_ptr<MoveOperation> operation_; |
| +}; |
| + |
| +TEST_F(MoveOperationTest, MoveFileInSameDirectory) { |
| + const base::FilePath src_path( |
| + FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| + const base::FilePath dest_path( |
| + FILE_PATH_LITERAL("drive/root/Directory 1/Test.log")); |
| + |
| + ResourceEntry src_entry; |
| + ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); |
| + |
|
hidehiko
2013/05/24 04:45:14
How about check
ASSERT_EQ(FILE_ERROR_NOT_FOUND, Ge
kinaba
2013/05/24 05:05:42
Sounds good. Done.
|
| + FileError error = FILE_ERROR_FAILED; |
| + operation_->Move(src_path, |
| + dest_path, |
| + google_apis::test_util::CreateCopyResultCallback(&error)); |
| + google_apis::test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(FILE_ERROR_OK, error); |
| + |
| + ResourceEntry dest_entry; |
| + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
| + EXPECT_EQ(src_entry.resource_id(), dest_entry.resource_id()); |
| + EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); |
| + |
| + EXPECT_EQ(1U, observer()->get_changed_paths().size()); |
| + EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); |
| +} |
| + |
| +TEST_F(MoveOperationTest, MoveFileFromRootToSubDirectory) { |
| + base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| + base::FilePath dest_path( |
| + FILE_PATH_LITERAL("drive/root/Directory 1/Test.log")); |
| + |
| + ResourceEntry src_entry; |
| + ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); |
| + |
| + FileError error = FILE_ERROR_FAILED; |
| + operation_->Move(src_path, |
| + dest_path, |
| + google_apis::test_util::CreateCopyResultCallback(&error)); |
| + google_apis::test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(FILE_ERROR_OK, error); |
| + |
| + ResourceEntry dest_entry; |
| + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
| + EXPECT_EQ(src_entry.resource_id(), dest_entry.resource_id()); |
| + EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); |
| + |
| + EXPECT_EQ(2U, observer()->get_changed_paths().size()); |
| + EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); |
| + EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); |
| +} |
| + |
| +TEST_F(MoveOperationTest, MoveFileFromSubDirectoryToRoot) { |
| + base::FilePath src_path( |
| + FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| + base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Test.log")); |
| + |
| + ResourceEntry src_entry; |
| + ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); |
| + |
| + FileError error = FILE_ERROR_FAILED; |
| + operation_->Move(src_path, |
| + dest_path, |
| + google_apis::test_util::CreateCopyResultCallback(&error)); |
| + google_apis::test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(FILE_ERROR_OK, error); |
| + |
| + ResourceEntry dest_entry; |
| + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
| + EXPECT_EQ(src_entry.resource_id(), dest_entry.resource_id()); |
| + EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); |
| + |
| + EXPECT_EQ(2U, observer()->get_changed_paths().size()); |
| + EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); |
| + EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); |
| +} |
| + |
| +TEST_F(MoveOperationTest, MoveFileBetweenSubDirectories) { |
| + base::FilePath src_path( |
| + FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| + base::FilePath dest_path( |
| + FILE_PATH_LITERAL("drive/root/Directory 1/Sub Directory Folder/Test")); |
| + |
| + ResourceEntry src_entry; |
| + ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); |
| + |
| + FileError error = FILE_ERROR_FAILED; |
| + operation_->Move(src_path, |
| + dest_path, |
| + google_apis::test_util::CreateCopyResultCallback(&error)); |
| + google_apis::test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(FILE_ERROR_OK, error); |
| + |
| + ResourceEntry dest_entry; |
| + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
| + EXPECT_EQ(src_entry.resource_id(), dest_entry.resource_id()); |
| + EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); |
| + |
| + EXPECT_EQ(2U, observer()->get_changed_paths().size()); |
| + EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); |
| + EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); |
| +} |
| + |
| +TEST_F(MoveOperationTest, MoveFileBetweenSubDirectoriesNoRename) { |
| + base::FilePath src_path( |
| + FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| + base::FilePath dest_path(FILE_PATH_LITERAL( |
| + "drive/root/Directory 1/Sub Directory Folder/SubDirectory File 1.txt")); |
| + |
| + ResourceEntry src_entry; |
| + ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); |
| + |
| + FileError error = FILE_ERROR_FAILED; |
| + operation_->Move(src_path, |
| + dest_path, |
| + google_apis::test_util::CreateCopyResultCallback(&error)); |
| + google_apis::test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(FILE_ERROR_OK, error); |
| + |
| + ResourceEntry dest_entry; |
| + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
| + EXPECT_EQ(src_entry.resource_id(), dest_entry.resource_id()); |
| + EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); |
| + |
| + EXPECT_EQ(2U, observer()->get_changed_paths().size()); |
| + EXPECT_TRUE(observer()->get_changed_paths().count(src_path.DirName())); |
| + EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); |
| +} |
| + |
| +TEST_F(MoveOperationTest, MoveNotExistingFile) { |
| + base::FilePath src_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); |
| + base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Test.log")); |
| + |
| + FileError error = FILE_ERROR_OK; |
| + operation_->Move(src_path, |
| + dest_path, |
| + google_apis::test_util::CreateCopyResultCallback(&error)); |
| + google_apis::test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); |
| + |
| + ResourceEntry entry; |
| + EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &entry)); |
| + EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); |
| +} |
| + |
| +TEST_F(MoveOperationTest, MoveFileToNonExistingDirectory) { |
| + base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| + base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Dummy/Test.log")); |
| + |
| + FileError error = FILE_ERROR_OK; |
| + operation_->Move(src_path, |
| + dest_path, |
| + google_apis::test_util::CreateCopyResultCallback(&error)); |
| + google_apis::test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); |
| + |
| + ResourceEntry entry; |
| + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); |
| + EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); |
| +} |
| + |
| +// Test the case where the parent of |dest_file_path| is a existing file, |
| +// not a directory. |
| +TEST_F(MoveOperationTest, MoveFileToInvalidPath) { |
| + base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| + base::FilePath dest_path( |
| + FILE_PATH_LITERAL("drive/root/Duplicate Name.txt/Test.log")); |
| + |
| + FileError error = FILE_ERROR_OK; |
| + operation_->Move(src_path, |
| + dest_path, |
| + google_apis::test_util::CreateCopyResultCallback(&error)); |
| + google_apis::test_util::RunBlockingPoolTask(); |
| + EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); |
| + |
| + ResourceEntry entry; |
| + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); |
| + EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); |
| +} |
| + |
| +} // namespace file_system |
| +} // namespace drive |