Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / content / public / test / sandbox_file_system_test_helper.h
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.
4
5 #ifndef CONTENT_PUBLIC_TEST_SANDBOX_FILE_SYSTEM_TEST_HELPER_H_
6 #define CONTENT_PUBLIC_TEST_SANDBOX_FILE_SYSTEM_TEST_HELPER_H_
7
8 #include <string>
9
10 #include "base/files/file_path.h"
11 #include "base/memory/ref_counted.h"
12 #include "storage/browser/fileapi/file_system_url.h"
13 #include "storage/browser/fileapi/file_system_usage_cache.h"
14 #include "storage/browser/fileapi/task_runner_bound_observer_list.h"
15 #include "storage/common/fileapi/file_system_types.h"
16 #include "storage/common/fileapi/file_system_util.h"
17 #include "storage/common/quota/quota_types.h"
18 #include "url/gurl.h"
19
20 namespace base {
21 class FilePath;
22 }
23
24 namespace storage {
25 class QuotaManagerProxy;
26 }
27
28 namespace storage {
29 class FileSystemContext;
30 class FileSystemFileUtil;
31 class FileSystemOperationContext;
32 class FileSystemOperationRunner;
33 }
34
35 namespace content {
36
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 {
41  public:
42   SandboxFileSystemTestHelper(const GURL& origin, storage::FileSystemType type);
43   SandboxFileSystemTestHelper();
44   ~SandboxFileSystemTestHelper();
45
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(storage::FileSystemContext* file_system_context);
52   void SetUp(const base::FilePath& base_dir,
53              storage::QuotaManagerProxy* quota_manager_proxy);
54   void TearDown();
55
56   base::FilePath GetOriginRootPath();
57   base::FilePath GetLocalPath(const base::FilePath& path);
58   base::FilePath GetLocalPathFromASCII(const std::string& path);
59
60   // Returns empty path if filesystem type is neither temporary nor persistent.
61   base::FilePath GetUsageCachePath() const;
62
63   storage::FileSystemURL CreateURL(const base::FilePath& path) const;
64   storage::FileSystemURL CreateURLFromUTF8(const std::string& utf8) const {
65     return CreateURL(base::FilePath::FromUTF8Unsafe(utf8));
66   }
67
68   // This returns cached usage size returned by QuotaUtil.
69   int64 GetCachedOriginUsage() const;
70
71   // This doesn't work with OFSFU.
72   int64 ComputeCurrentOriginUsage();
73
74   int64 ComputeCurrentDirectoryDatabaseUsage();
75
76   storage::FileSystemOperationRunner* operation_runner();
77   storage::FileSystemOperationContext* NewOperationContext();
78
79   void AddFileChangeObserver(storage::FileChangeObserver* observer);
80   void AddFileUpdateObserver(storage::FileUpdateObserver* observer);
81
82   storage::FileSystemContext* file_system_context() const {
83     return file_system_context_.get();
84   }
85
86   const GURL& origin() const { return origin_; }
87   storage::FileSystemType type() const { return type_; }
88   storage::StorageType storage_type() const {
89     return storage::FileSystemTypeToQuotaStorageType(type_);
90   }
91   storage::FileSystemFileUtil* file_util() const { return file_util_; }
92   storage::FileSystemUsageCache* usage_cache();
93
94  private:
95   void SetUpFileSystem();
96
97   scoped_refptr<storage::FileSystemContext> file_system_context_;
98
99   const GURL origin_;
100   const storage::FileSystemType type_;
101   storage::FileSystemFileUtil* file_util_;
102 };
103
104 }  // namespace content
105
106 #endif  // CONTENT_PUBLIC_TEST_SANDBOX_FILE_SYSTEM_TEST_HELPER_H_