1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_TEST_SANDBOX_FILE_SYSTEM_TEST_HELPER_H_
6 #define CONTENT_PUBLIC_TEST_SANDBOX_FILE_SYSTEM_TEST_HELPER_H_
10 #include "base/files/file_path.h"
11 #include "base/memory/ref_counted.h"
13 #include "webkit/browser/fileapi/file_system_url.h"
14 #include "webkit/browser/fileapi/file_system_usage_cache.h"
15 #include "webkit/browser/fileapi/task_runner_bound_observer_list.h"
16 #include "webkit/common/fileapi/file_system_types.h"
17 #include "webkit/common/fileapi/file_system_util.h"
18 #include "webkit/common/quota/quota_types.h"
25 class QuotaManagerProxy;
30 class FileSystemContext;
31 class FileSystemFileUtil;
32 class FileSystemOperationContext;
33 class FileSystemOperationRunner;
35 // Filesystem test helper class that encapsulates test environment for
36 // a given {origin, type} pair. This helper only works for sandboxed
37 // file systems (Temporary or Persistent).
38 class SandboxFileSystemTestHelper {
40 SandboxFileSystemTestHelper(const GURL& origin, FileSystemType type);
41 SandboxFileSystemTestHelper();
42 ~SandboxFileSystemTestHelper();
44 void SetUp(const base::FilePath& base_dir);
45 // If you want to use more than one SandboxFileSystemTestHelper in
46 // a single base directory, they have to share a context, so that they don't
47 // have multiple databases fighting over the lock to the origin directory
48 // [deep down inside ObfuscatedFileUtil].
49 void SetUp(FileSystemContext* file_system_context);
50 void SetUp(const base::FilePath& base_dir,
51 quota::QuotaManagerProxy* quota_manager_proxy);
54 base::FilePath GetOriginRootPath();
55 base::FilePath GetLocalPath(const base::FilePath& path);
56 base::FilePath GetLocalPathFromASCII(const std::string& path);
58 // Returns empty path if filesystem type is neither temporary nor persistent.
59 base::FilePath GetUsageCachePath() const;
61 FileSystemURL CreateURL(const base::FilePath& path) const;
62 FileSystemURL CreateURLFromUTF8(const std::string& utf8) const {
63 return CreateURL(base::FilePath::FromUTF8Unsafe(utf8));
66 // This returns cached usage size returned by QuotaUtil.
67 int64 GetCachedOriginUsage() const;
69 // This doesn't work with OFSFU.
70 int64 ComputeCurrentOriginUsage();
72 int64 ComputeCurrentDirectoryDatabaseUsage();
74 FileSystemOperationRunner* operation_runner();
75 FileSystemOperationContext* NewOperationContext();
77 void AddFileChangeObserver(FileChangeObserver* observer);
79 FileSystemContext* file_system_context() const {
80 return file_system_context_.get();
83 const GURL& origin() const { return origin_; }
84 FileSystemType type() const { return type_; }
85 quota::StorageType storage_type() const {
86 return FileSystemTypeToQuotaStorageType(type_);
88 FileSystemFileUtil* file_util() const { return file_util_; }
89 FileSystemUsageCache* usage_cache();
92 void SetUpFileSystem();
94 scoped_refptr<FileSystemContext> file_system_context_;
97 const FileSystemType type_;
98 FileSystemFileUtil* file_util_;
101 } // namespace fileapi
103 #endif // CONTENT_PUBLIC_TEST_SANDBOX_FILE_SYSTEM_TEST_HELPER_H_