1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef STORAGE_BROWSER_TEST_ASYNC_FILE_TEST_HELPER_H_
#define STORAGE_BROWSER_TEST_ASYNC_FILE_TEST_HELPER_H_
#include <stddef.h>
#include <stdint.h>
#include <string_view>
#include "storage/browser/file_system/file_system_operation.h"
#include "storage/common/file_system/file_system_types.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
namespace blink {
class StorageKey;
}
namespace storage {
class FileSystemContext;
class FileSystemURL;
class QuotaManagerProxy;
}
namespace storage {
// A helper class to perform async file operations in a synchronous way.
class AsyncFileTestHelper {
public:
using FileEntryList = FileSystemOperation::FileEntryList;
static const int64_t kDontCheckSize;
// Performs Copy from |src| to |dest| and returns the status code.
static base::File::Error Copy(FileSystemContext* context,
const FileSystemURL& src,
const FileSystemURL& dest);
// Same as Copy, but this supports |copy_or_move_hook_delegate|.
static base::File::Error CopyWithHookDelegate(
FileSystemContext* context,
const FileSystemURL& src,
const FileSystemURL& dest,
FileSystemOperation::ErrorBehavior error_behavior,
std::unique_ptr<CopyOrMoveHookDelegate> copy_or_move_hook_delegate);
// Performs CopyFileLocal from |src| to |dest| and returns the status code.
static base::File::Error CopyFileLocal(FileSystemContext* context,
const FileSystemURL& src,
const FileSystemURL& dest);
// Performs Move from |src| to |dest| and returns the status code.
static base::File::Error Move(FileSystemContext* context,
const FileSystemURL& src,
const FileSystemURL& dest);
// Same as Move, but this supports |copy_or_move_hook_delegate|.
static base::File::Error MoveWithHookDelegate(
FileSystemContext* context,
const FileSystemURL& src,
const FileSystemURL& dest,
FileSystemOperation::ErrorBehavior error_behavior,
std::unique_ptr<CopyOrMoveHookDelegate> copy_or_move_hook_delegate);
// Performs MoveFileLocal from |src| to |dest| and returns the status code.
static base::File::Error MoveFileLocal(FileSystemContext* context,
const FileSystemURL& src,
const FileSystemURL& dest);
// Removes the given |url|.
static base::File::Error Remove(FileSystemContext* context,
const FileSystemURL& url,
bool recursive);
// Performs ReadDirectory on |url|.
static base::File::Error ReadDirectory(FileSystemContext* context,
const FileSystemURL& url,
FileEntryList* entries);
// Creates a directory at |url|.
static base::File::Error CreateDirectory(FileSystemContext* context,
const FileSystemURL& url);
// Creates a file at |url|.
static base::File::Error CreateFile(FileSystemContext* context,
const FileSystemURL& url);
// Creates a file at |url| and fills with |buf|.
static base::File::Error CreateFileWithData(FileSystemContext* context,
const FileSystemURL& url,
std::string_view data);
// Truncates the file |url| to |size|.
static base::File::Error TruncateFile(FileSystemContext* context,
const FileSystemURL& url,
size_t size);
// Retrieves File::Info for |url| and populates |file_info|.
static base::File::Error GetMetadata(FileSystemContext* context,
const FileSystemURL& url,
base::File::Info* file_info);
// Retrieves FilePath for |url| and populates |platform_path|.
static base::File::Error GetPlatformPath(FileSystemContext* context,
const FileSystemURL& url,
base::FilePath* platform_path);
// Returns true if a file exists at |url| with |size|. If |size| is
// kDontCheckSize it doesn't check the file size (but just check its
// existence).
static bool FileExists(FileSystemContext* context,
const FileSystemURL& url,
int64_t size);
// Returns true if a directory exists at |url|.
static bool DirectoryExists(FileSystemContext* context,
const FileSystemURL& url);
// Returns usage and quota. It's valid to pass nullptr to |usage| and/or
// |quota|.
static blink::mojom::QuotaStatusCode GetUsageAndQuota(
QuotaManagerProxy* quota_manager_proxy,
const blink::StorageKey& storage_key,
FileSystemType type,
int64_t* usage,
int64_t* quota);
// Modifies timestamps of a file or directory at |url| with
// |last_access_time| and |last_modified_time|. The function DOES NOT
// create a file unlike 'touch' command on Linux.
static base::File::Error TouchFile(FileSystemContext* context,
const FileSystemURL& url,
const base::Time& last_access_time,
const base::Time& last_modified_time);
};
} // namespace storage
#endif // STORAGE_BROWSER_TEST_ASYNC_FILE_TEST_HELPER_H_
|