X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fchrome%2Fbrowser%2Fchromeos%2Fdrive%2Ffile_system%2Fcopy_operation_unittest.cc;h=2416ac875b9fb96e627e7b0a2bbcc4632ebf8933;hb=ff3e2503a20db9193d323c1d19c38c68004dec4a;hp=28494b50b3a0173f913c6f15292239110aabfe0c;hpb=7338fba38ba696536d1cc9d389afd716a6ab2fe6;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc b/src/chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc index 28494b5..2416ac8 100644 --- a/src/chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc +++ b/src/chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc @@ -4,6 +4,7 @@ #include "chrome/browser/chromeos/drive/file_system/copy_operation.h" +#include "base/file_util.h" #include "base/task_runner_util.h" #include "chrome/browser/chromeos/drive/file_cache.h" #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" @@ -79,20 +80,17 @@ TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_RegularFile) { remote_dest_path.DirName())); } -TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_QuotaCheck) { +TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_Overwrite) { const base::FilePath local_src_path = temp_dir().AppendASCII("local.txt"); const base::FilePath remote_dest_path( - FILE_PATH_LITERAL("drive/root/remote.txt")); - - const size_t kFileSize = 10; + FILE_PATH_LITERAL("drive/root/File 1.txt")); // Prepare a local file. - ASSERT_TRUE( - google_apis::test_util::WriteStringToFile(local_src_path, - std::string(kFileSize, 'a'))); - - // Set insufficient quota. - fake_service()->SetQuotaValue(100, 100 + kFileSize - 1); + EXPECT_TRUE( + google_apis::test_util::WriteStringToFile(local_src_path, "hello")); + // Confirm that the remote file exists. + ResourceEntry entry; + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); // Transfer the local file to Drive. FileError error = FILE_ERROR_FAILED; @@ -101,19 +99,28 @@ TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_QuotaCheck) { remote_dest_path, google_apis::test_util::CreateCopyResultCallback(&error)); test_util::RunBlockingPoolTask(); - EXPECT_EQ(FILE_ERROR_NO_SERVER_SPACE, error); - - // Set sufficient quota. - fake_service()->SetQuotaValue(100, 100 + kFileSize); + EXPECT_EQ(FILE_ERROR_OK, error); - // Transfer the local file to Drive. - error = FILE_ERROR_FAILED; - operation_->TransferFileFromLocalToRemote( - local_src_path, - remote_dest_path, - google_apis::test_util::CreateCopyResultCallback(&error)); + // TransferFileFromLocalToRemote stores a copy of the local file in the cache, + // marks it dirty and requests the observer to upload the file. + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); + EXPECT_EQ(1U, observer()->updated_local_ids().count(entry.local_id())); + FileCacheEntry cache_entry; + bool found = false; + base::PostTaskAndReplyWithResult( + blocking_task_runner(), + FROM_HERE, + base::Bind(&internal::FileCache::GetCacheEntry, + base::Unretained(cache()), entry.local_id(), &cache_entry), + google_apis::test_util::CreateCopyResultCallback(&found)); test_util::RunBlockingPoolTask(); - EXPECT_EQ(FILE_ERROR_OK, error); + EXPECT_TRUE(found); + EXPECT_TRUE(cache_entry.is_present()); + EXPECT_TRUE(cache_entry.is_dirty()); + + EXPECT_EQ(1U, observer()->get_changed_paths().size()); + EXPECT_TRUE(observer()->get_changed_paths().count( + remote_dest_path.DirName())); } TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_HostedDocument) { @@ -217,6 +224,121 @@ TEST_F(CopyOperationTest, CopyFileToInvalidPath) { EXPECT_TRUE(observer()->get_changed_paths().empty()); } +TEST_F(CopyOperationTest, CopyDirtyFile) { + base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); + base::FilePath dest_path(FILE_PATH_LITERAL( + "drive/root/Directory 1/New File.txt")); + + ResourceEntry src_entry; + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); + + // Store a dirty cache file. + base::FilePath temp_file; + EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_dir(), &temp_file)); + std::string contents = "test content"; + EXPECT_TRUE(google_apis::test_util::WriteStringToFile(temp_file, contents)); + FileError error = FILE_ERROR_FAILED; + base::PostTaskAndReplyWithResult( + blocking_task_runner(), + FROM_HERE, + base::Bind(&internal::FileCache::Store, + base::Unretained(cache()), + src_entry.local_id(), + std::string(), + temp_file, + internal::FileCache::FILE_OPERATION_MOVE), + google_apis::test_util::CreateCopyResultCallback(&error)); + test_util::RunBlockingPoolTask(); + EXPECT_EQ(FILE_ERROR_OK, error); + + // Copy. + operation_->Copy(src_path, + dest_path, + false, + google_apis::test_util::CreateCopyResultCallback(&error)); + test_util::RunBlockingPoolTask(); + EXPECT_EQ(FILE_ERROR_OK, error); + + ResourceEntry dest_entry; + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); + EXPECT_EQ(ResourceEntry::DIRTY, dest_entry.metadata_edit_state()); + + EXPECT_EQ(1u, observer()->updated_local_ids().size()); + EXPECT_TRUE(observer()->updated_local_ids().count(dest_entry.local_id())); + EXPECT_EQ(1u, observer()->get_changed_paths().size()); + EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); + + // Copied cache file should be dirty. + bool success = false; + FileCacheEntry cache_entry; + base::PostTaskAndReplyWithResult( + blocking_task_runner(), + FROM_HERE, + base::Bind(&internal::FileCache::GetCacheEntry, + base::Unretained(cache()), + dest_entry.local_id(), + &cache_entry), + google_apis::test_util::CreateCopyResultCallback(&success)); + test_util::RunBlockingPoolTask(); + EXPECT_TRUE(success); + EXPECT_TRUE(cache_entry.is_dirty()); + + // File contents should match. + base::FilePath cache_file_path; + base::PostTaskAndReplyWithResult( + blocking_task_runner(), + FROM_HERE, + base::Bind(&internal::FileCache::GetFile, + base::Unretained(cache()), + dest_entry.local_id(), + &cache_file_path), + google_apis::test_util::CreateCopyResultCallback(&error)); + test_util::RunBlockingPoolTask(); + EXPECT_EQ(FILE_ERROR_OK, error); + + std::string copied_contents; + EXPECT_TRUE(base::ReadFileToString(cache_file_path, &copied_contents)); + EXPECT_EQ(contents, copied_contents); +} + +TEST_F(CopyOperationTest, CopyFileOverwriteFile) { + base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); + base::FilePath dest_path(FILE_PATH_LITERAL( + "drive/root/Directory 1/SubDirectory File 1.txt")); + + ResourceEntry old_dest_entry; + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &old_dest_entry)); + + FileError error = FILE_ERROR_OK; + operation_->Copy(src_path, + dest_path, + false, + google_apis::test_util::CreateCopyResultCallback(&error)); + test_util::RunBlockingPoolTask(); + EXPECT_EQ(FILE_ERROR_OK, error); + + ResourceEntry new_dest_entry; + EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &new_dest_entry)); + + EXPECT_EQ(1u, observer()->updated_local_ids().size()); + EXPECT_TRUE(observer()->updated_local_ids().count(old_dest_entry.local_id())); + EXPECT_EQ(1u, observer()->get_changed_paths().size()); + EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); +} + +TEST_F(CopyOperationTest, CopyFileOverwriteDirectory) { + base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); + base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Directory 1")); + + FileError error = FILE_ERROR_OK; + operation_->Copy(src_path, + dest_path, + false, + google_apis::test_util::CreateCopyResultCallback(&error)); + test_util::RunBlockingPoolTask(); + EXPECT_EQ(FILE_ERROR_INVALID_OPERATION, error); +} + TEST_F(CopyOperationTest, CopyDirectory) { base::FilePath src_path(FILE_PATH_LITERAL("drive/root/Directory 1")); base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/New Directory"));