#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include <stddef.h>
#include <stdint.h>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/containers/contains.h"
#include "base/containers/queue.h"
#include "base/containers/span.h"
#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/memory/scoped_refptr.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/task_environment.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "components/file_access/file_access_copy_or_move_delegate_factory.h"
#include "components/services/filesystem/public/mojom/types.mojom.h"
#include "storage/browser/file_system/copy_or_move_file_validator.h"
#include "storage/browser/file_system/copy_or_move_hook_delegate.h"
#include "storage/browser/file_system/copy_or_move_operation_delegate.h"
#include "storage/browser/file_system/file_stream_reader.h"
#include "storage/browser/file_system/file_stream_writer.h"
#include "storage/browser/file_system/file_system_backend.h"
#include "storage/browser/file_system/file_system_context.h"
#include "storage/browser/file_system/file_system_operation.h"
#include "storage/browser/file_system/file_system_url.h"
#include "storage/browser/file_system/file_system_util.h"
#include "storage/browser/quota/quota_manager.h"
#include "storage/browser/test/async_file_test_helper.h"
#include "storage/browser/test/file_system_test_file_set.h"
#include "storage/browser/test/mock_copy_or_move_hook_delegate.h"
#include "storage/browser/test/mock_quota_manager.h"
#include "storage/browser/test/mock_quota_manager_proxy.h"
#include "storage/browser/test/mock_special_storage_policy.h"
#include "storage/browser/test/test_file_system_backend.h"
#include "storage/browser/test/test_file_system_context.h"
#include "storage/common/file_system/file_system_mount_option.h"
#include "storage/common/file_system/file_system_types.h"
#include "storage/common/file_system/file_system_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "url/gurl.h"
#include "url/origin.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/test/android/content_uri_test_utils.h"
#endif
namespace storage {
namespace {
FileEntryList;
constexpr int64_t kDefaultFileSize = …;
void ExpectOk(const GURL& origin_url,
const std::string& name,
base::File::Error error) { … }
class TestValidatorFactory : public CopyOrMoveFileValidatorFactory { … };
class CopyOrMoveRecordAndSecurityDelegate : public CopyOrMoveHookDelegate { … };
void RecordFileProgressCallback(std::vector<int64_t>* records,
int64_t progress) { … }
void AssignAndQuit(base::RunLoop* run_loop,
base::File::Error* result_out,
base::File::Error result) { … }
class ScopedThreadStopper { … };
class CopyOrMoveOperationTestHelper { … };
}
class LocalFileSystemCopyOrMoveOperationTest
: public ::testing::TestWithParam<std::tuple< bool,
bool,
bool>> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(LocalFileSystemCopyOrMoveOperationTest, SingleFile) { … }
TEST_P(LocalFileSystemCopyOrMoveOperationTest, EmptyDirectory) { … }
TEST_P(LocalFileSystemCopyOrMoveOperationTest, FilesAndDirectories) { … }
TEST(LocalFileSystemCopyOrMoveOperationTest,
MoveDirectoryFailPostWriteValidation) { … }
TEST(LocalFileSystemCopyOrMoveOperationTest, CopySingleFileNoValidator) { … }
#if BUILDFLAG(IS_ANDROID)
TEST(LocalFileSystemCopyOrMoveOperationTest, CopyToExistingContentUri) {
base::test::TaskEnvironment task_environment(
base::test::TaskEnvironment::MainThreadType::IO);
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
base::FilePath source_path = temp_dir.GetPath().Append("source");
base::FilePath dest_path = temp_dir.GetPath().Append("dest");
base::WriteFile(source_path, "foobar");
base::WriteFile(dest_path, "will-be-truncated");
base::FilePath source_content_uri;
ASSERT_TRUE(base::test::android::GetContentUriFromCacheDirFilePath(
source_path, &source_content_uri));
base::FilePath dest_content_uri;
ASSERT_TRUE(base::test::android::GetContentUriFromCacheDirFilePath(
dest_path, &dest_content_uri));
auto storage_key =
blink::StorageKey::CreateFromStringForTesting("http://foo");
auto file_system_context =
storage::CreateFileSystemContextForTesting(nullptr, temp_dir.GetPath());
FileSystemURL src = file_system_context->CreateCrackedFileSystemURL(
storage_key, kFileSystemTypeLocal, source_content_uri);
FileSystemURL dest = file_system_context->CreateCrackedFileSystemURL(
storage_key, kFileSystemTypeLocal, dest_content_uri);
EXPECT_EQ(base::File::FILE_OK,
AsyncFileTestHelper::Copy(file_system_context.get(), src, dest));
EXPECT_TRUE(
AsyncFileTestHelper::FileExists(file_system_context.get(), src, 6));
EXPECT_TRUE(
AsyncFileTestHelper::FileExists(file_system_context.get(), dest, 6));
}
#endif
TEST_P(LocalFileSystemCopyOrMoveOperationTest, FilesAndDirectoriesProgress) { … }
TEST(LocalFileSystemCopyOrMoveOperationTest, StreamCopyHelper) { … }
TEST(LocalFileSystemCopyOrMoveOperationTest, StreamCopyHelperWithFlush) { … }
TEST(LocalFileSystemCopyOrMoveOperationTest, StreamCopyHelper_Cancel) { … }
class CopyOrMoveOperationDelegateTestHelper { … };
TEST(CopyOrMoveOperationDelegateTest, StopRecursionOnCopyError) { … }
TEST(CopyOrMoveOperationDelegateTest, ContinueRecursionOnCopyIgnored) { … }
TEST(CopyOrMoveOperationDelegateTest, ContinueRecursionOnMoveIgnored) { … }
TEST(CopyOrMoveOperationDelegateTest, RemoveDestFileOnCopyError) { … }
TEST(CopyOrMoveOperationDelegateTest,
RemoveDestFileOnCrossFilesystemMoveError) { … }
class MockFileAccessCopyOrMoveDelegateFactory
: public file_access::FileAccessCopyOrMoveDelegateFactory { … };
TEST(CopyOrMoveOperationDelegateTest, InjectHook) { … }
}