1 // Copyright (c) 2012 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 WEBKIT_FILEAPI_SANDBOX_FILE_SYSTEM_TEST_HELPER_H_
6 #define WEBKIT_FILEAPI_SANDBOX_FILE_SYSTEM_TEST_HELPER_H_
10 #include "base/files/file_path.h"
11 #include "base/memory/ref_counted.h"
12 #include "googleurl/src/gurl.h"
13 #include "webkit/browser/fileapi/file_system_usage_cache.h"
14 #include "webkit/fileapi/file_system_types.h"
15 #include "webkit/fileapi/file_system_url.h"
16 #include "webkit/fileapi/file_system_util.h"
17 #include "webkit/quota/quota_types.h"
24 class QuotaManagerProxy
;
29 class FileSystemContext
;
30 class FileSystemFileUtil
;
31 class FileSystemOperationContext
;
32 class LocalFileSystemOperation
;
34 // Filesystem test helper class that encapsulates test environment for
35 // a given {origin, type} pair. This helper only works for sandboxed
36 // file systems (Temporary or Persistent).
37 class SandboxFileSystemTestHelper
{
39 SandboxFileSystemTestHelper(const GURL
& origin
, FileSystemType type
);
40 SandboxFileSystemTestHelper();
41 ~SandboxFileSystemTestHelper();
43 void SetUp(const base::FilePath
& base_dir
);
44 // If you want to use more than one SandboxFileSystemTestHelper in
45 // a single base directory, they have to share a context, so that they don't
46 // have multiple databases fighting over the lock to the origin directory
47 // [deep down inside ObfuscatedFileUtil].
48 void SetUp(FileSystemContext
* file_system_context
);
49 void SetUp(const base::FilePath
& base_dir
,
50 quota::QuotaManagerProxy
* quota_manager_proxy
);
53 base::FilePath
GetOriginRootPath() const;
54 base::FilePath
GetLocalPath(const base::FilePath
& path
);
55 base::FilePath
GetLocalPathFromASCII(const std::string
& path
);
57 // Returns empty path if filesystem type is neither temporary nor persistent.
58 base::FilePath
GetUsageCachePath() const;
60 FileSystemURL
CreateURL(const base::FilePath
& path
) const;
61 FileSystemURL
CreateURLFromUTF8(const std::string
& utf8
) const {
62 return CreateURL(base::FilePath::FromUTF8Unsafe(utf8
));
65 // This returns cached usage size returned by QuotaUtil.
66 int64
GetCachedOriginUsage() const;
68 // This doesn't work with OFSFU.
69 int64
ComputeCurrentOriginUsage();
71 int64
ComputeCurrentDirectoryDatabaseUsage() const;
73 LocalFileSystemOperation
* NewOperation();
74 FileSystemOperationContext
* NewOperationContext();
76 FileSystemContext
* file_system_context() const {
77 return file_system_context_
.get();
80 const GURL
& origin() const { return origin_
; }
81 FileSystemType
type() const { return type_
; }
82 quota::StorageType
storage_type() const {
83 return FileSystemTypeToQuotaStorageType(type_
);
85 FileSystemFileUtil
* file_util() const { return file_util_
; }
86 FileSystemUsageCache
* usage_cache();
89 void SetUpFileSystem();
91 scoped_refptr
<FileSystemContext
> file_system_context_
;
94 const FileSystemType type_
;
95 FileSystemFileUtil
* file_util_
;
98 } // namespace fileapi
100 #endif // WEBKIT_FILEAPI_SANDBOX_FILE_SYSTEM_TEST_HELPER_H_