Commit ccce250d authored by mtomasz@chromium.org's avatar mtomasz@chromium.org

[fsp] Refactor FakeProvidedFileSystem to be more flexible.

Before, the FakeProvidedFileSystem had some hardcoded responses. However, since
FileStreamWriter is coming soon, we will need to verify if the file on the
file system is changed correctly.

For that, FakeProvidedFileSystem has been refactored, so it is possible to add
and get fake files and verify their values.

TEST=unit_tests: *FileSystemProvider*
BUG=391362

Review URL: https://codereview.chromium.org/393233002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283538 0039d316-1c4b-4281-b951-d872f2087c98
parent f147ae30
...@@ -13,6 +13,10 @@ ...@@ -13,6 +13,10 @@
class Profile; class Profile;
namespace base {
class Time;
} // namespace base
namespace net { namespace net {
class IOBuffer; class IOBuffer;
} // namespace net } // namespace net
...@@ -22,11 +26,22 @@ namespace file_system_provider { ...@@ -22,11 +26,22 @@ namespace file_system_provider {
class RequestManager; class RequestManager;
extern const char kFakeFileName[]; // Path of a sample fake file, which is added to the fake file system by
// default.
extern const char kFakeFilePath[]; extern const char kFakeFilePath[];
extern const char kFakeFileText[];
extern const size_t kFakeFileSize; // Represents a file or a directory on a fake file system.
extern const char kFakeFileModificationTime[]; struct FakeEntry {
FakeEntry() {}
FakeEntry(EntryMetadata& metadata, const std::string& contents)
: metadata(metadata), contents(contents) {}
virtual ~FakeEntry() {}
EntryMetadata metadata;
std::string contents;
};
// Fake provided file system implementation. Does not communicate with target // Fake provided file system implementation. Does not communicate with target
// extensions. Used for unit tests. // extensions. Used for unit tests.
...@@ -36,6 +51,20 @@ class FakeProvidedFileSystem : public ProvidedFileSystemInterface { ...@@ -36,6 +51,20 @@ class FakeProvidedFileSystem : public ProvidedFileSystemInterface {
const ProvidedFileSystemInfo& file_system_info); const ProvidedFileSystemInfo& file_system_info);
virtual ~FakeProvidedFileSystem(); virtual ~FakeProvidedFileSystem();
// Adds a fake entry to the fake file system.
void AddEntry(const base::FilePath& entry_path,
bool is_directory,
const std::string& name,
int64 size,
base::Time modification_time,
std::string mime_type,
std::string contents);
// Fetches a pointer to a fake entry registered in the fake file system. If
// found, then the result is written to |fake_entry| and true is returned.
// Otherwise, false is returned. |fake_entry| must not be NULL.
bool GetEntry(const base::FilePath& entry_path, FakeEntry* fake_entry) const;
// ProvidedFileSystemInterface overrides. // ProvidedFileSystemInterface overrides.
virtual void RequestUnmount( virtual void RequestUnmount(
const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE; const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
...@@ -77,9 +106,11 @@ class FakeProvidedFileSystem : public ProvidedFileSystemInterface { ...@@ -77,9 +106,11 @@ class FakeProvidedFileSystem : public ProvidedFileSystemInterface {
const ProvidedFileSystemInfo& file_system_info); const ProvidedFileSystemInfo& file_system_info);
private: private:
typedef std::map<base::FilePath, FakeEntry> Entries;
typedef std::map<int, base::FilePath> OpenedFilesMap; typedef std::map<int, base::FilePath> OpenedFilesMap;
ProvidedFileSystemInfo file_system_info_; ProvidedFileSystemInfo file_system_info_;
Entries entries_;
OpenedFilesMap opened_files_; OpenedFilesMap opened_files_;
int last_file_handle_; int last_file_handle_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment