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
;
29 class FileSystemContext
;
30 class FileSystemFileUtil
;
31 class FileSystemOperationContext
;
32 class FileSystemOperationRunner
;
37 // Filesystem test helper class that encapsulates test environment for
38 // a given {origin, type} pair. This helper only works for sandboxed
39 // file systems (Temporary or Persistent).
40 class SandboxFileSystemTestHelper
{
42 SandboxFileSystemTestHelper(const GURL
& origin
, fileapi::FileSystemType type
);
43 SandboxFileSystemTestHelper();
44 ~SandboxFileSystemTestHelper();
46 void SetUp(const base::FilePath
& base_dir
);
47 // If you want to use more than one SandboxFileSystemTestHelper in
48 // a single base directory, they have to share a context, so that they don't
49 // have multiple databases fighting over the lock to the origin directory
50 // [deep down inside ObfuscatedFileUtil].
51 void SetUp(fileapi::FileSystemContext
* file_system_context
);
52 void SetUp(const base::FilePath
& base_dir
,
53 quota::QuotaManagerProxy
* quota_manager_proxy
);
56 base::FilePath
GetOriginRootPath();
57 base::FilePath
GetLocalPath(const base::FilePath
& path
);
58 base::FilePath
GetLocalPathFromASCII(const std::string
& path
);
60 // Returns empty path if filesystem type is neither temporary nor persistent.
61 base::FilePath
GetUsageCachePath() const;
63 fileapi::FileSystemURL
CreateURL(const base::FilePath
& path
) const;
64 fileapi::FileSystemURL
CreateURLFromUTF8(const std::string
& utf8
) const {
65 return CreateURL(base::FilePath::FromUTF8Unsafe(utf8
));
68 // This returns cached usage size returned by QuotaUtil.
69 int64
GetCachedOriginUsage() const;
71 // This doesn't work with OFSFU.
72 int64
ComputeCurrentOriginUsage();
74 int64
ComputeCurrentDirectoryDatabaseUsage();
76 fileapi::FileSystemOperationRunner
* operation_runner();
77 fileapi::FileSystemOperationContext
* NewOperationContext();
79 void AddFileChangeObserver(fileapi::FileChangeObserver
* observer
);
81 fileapi::FileSystemContext
* file_system_context() const {
82 return file_system_context_
.get();
85 const GURL
& origin() const { return origin_
; }
86 fileapi::FileSystemType
type() const { return type_
; }
87 quota::StorageType
storage_type() const {
88 return fileapi::FileSystemTypeToQuotaStorageType(type_
);
90 fileapi::FileSystemFileUtil
* file_util() const { return file_util_
; }
91 fileapi::FileSystemUsageCache
* usage_cache();
94 void SetUpFileSystem();
96 scoped_refptr
<fileapi::FileSystemContext
> file_system_context_
;
99 const fileapi::FileSystemType type_
;
100 fileapi::FileSystemFileUtil
* file_util_
;
103 } // namespace content
105 #endif // CONTENT_PUBLIC_TEST_SANDBOX_FILE_SYSTEM_TEST_HELPER_H_