| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/fileapi/file_system_test_helper.h" | 5 #include "webkit/fileapi/file_system_test_helper.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 11 #include "webkit/fileapi/file_system_context.h" | 11 #include "webkit/fileapi/file_system_context.h" |
| 12 #include "webkit/fileapi/file_system_operation.h" | 12 #include "webkit/fileapi/file_system_operation.h" |
| 13 #include "webkit/fileapi/file_system_operation_context.h" | 13 #include "webkit/fileapi/file_system_operation_context.h" |
| 14 #include "webkit/fileapi/file_system_options.h" |
| 14 #include "webkit/fileapi/file_system_usage_cache.h" | 15 #include "webkit/fileapi/file_system_usage_cache.h" |
| 15 #include "webkit/fileapi/file_system_util.h" | 16 #include "webkit/fileapi/file_system_util.h" |
| 16 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 17 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 17 #include "webkit/quota/mock_special_storage_policy.h" | 18 #include "webkit/quota/mock_special_storage_policy.h" |
| 18 | 19 |
| 19 namespace fileapi { | 20 namespace fileapi { |
| 20 | 21 |
| 22 namespace { |
| 23 |
| 24 class TestHelperOptions : public FileSystemOptions { |
| 25 public: |
| 26 explicit TestHelperOptions(bool is_incognito) : is_incognito_(is_incognito) {} |
| 27 virtual bool is_incognito() const OVERRIDE { return is_incognito_; } |
| 28 virtual bool allow_file_access_from_files() const OVERRIDE { return true; } |
| 29 private: |
| 30 bool is_incognito_; |
| 31 }; |
| 32 |
| 33 } // namespace |
| 34 |
| 21 FileSystemTestOriginHelper::FileSystemTestOriginHelper( | 35 FileSystemTestOriginHelper::FileSystemTestOriginHelper( |
| 22 const GURL& origin, FileSystemType type) | 36 const GURL& origin, FileSystemType type) |
| 23 : origin_(origin), type_(type), file_util_(NULL) { | 37 : origin_(origin), type_(type), file_util_(NULL) { |
| 24 } | 38 } |
| 25 | 39 |
| 26 FileSystemTestOriginHelper::FileSystemTestOriginHelper() | 40 FileSystemTestOriginHelper::FileSystemTestOriginHelper() |
| 27 : origin_(GURL("http://foo.com")), | 41 : origin_(GURL("http://foo.com")), |
| 28 type_(kFileSystemTypeTemporary), | 42 type_(kFileSystemTypeTemporary), |
| 29 file_util_(NULL) { | 43 file_util_(NULL) { |
| 30 } | 44 } |
| 31 | 45 |
| 32 FileSystemTestOriginHelper::~FileSystemTestOriginHelper() { | 46 FileSystemTestOriginHelper::~FileSystemTestOriginHelper() { |
| 33 } | 47 } |
| 34 | 48 |
| 35 void FileSystemTestOriginHelper::SetUp( | 49 void FileSystemTestOriginHelper::SetUp( |
| 36 const FilePath& base_dir, FileSystemFileUtil* file_util) { | 50 const FilePath& base_dir, FileSystemFileUtil* file_util) { |
| 37 SetUp(base_dir, false, false, NULL, file_util); | 51 SetUp(base_dir, false, false, NULL, file_util); |
| 38 } | 52 } |
| 39 | 53 |
| 40 void FileSystemTestOriginHelper::SetUp( | 54 void FileSystemTestOriginHelper::SetUp( |
| 41 FileSystemContext* file_system_context, FileSystemFileUtil* file_util) { | 55 FileSystemContext* file_system_context, FileSystemFileUtil* file_util) { |
| 42 DCHECK(file_system_context->path_manager()); | 56 DCHECK(file_system_context->sandbox_provider()); |
| 43 DCHECK(file_system_context->path_manager()->sandbox_provider()); | |
| 44 | 57 |
| 45 file_util_ = file_util; | 58 file_util_ = file_util; |
| 46 file_system_context_ = file_system_context; | 59 file_system_context_ = file_system_context; |
| 47 if (!file_util_) | 60 if (!file_util_) |
| 48 file_util_ = file_system_context->path_manager()->sandbox_provider()-> | 61 file_util_ = file_system_context->sandbox_provider()->GetFileUtil(); |
| 49 GetFileUtil(); | |
| 50 DCHECK(file_util_); | 62 DCHECK(file_util_); |
| 51 | 63 |
| 52 // Prepare the origin's root directory. | 64 // Prepare the origin's root directory. |
| 53 file_system_context_->path_manager()-> | 65 file_system_context_->GetMountPointProvider(type_)-> |
| 54 ValidateFileSystemRootAndGetPathOnFileThread( | 66 ValidateFileSystemRootAndGetPathOnFileThread( |
| 55 origin_, type_, FilePath(), true /* create */); | 67 origin_, type_, FilePath(), true /* create */); |
| 56 | 68 |
| 57 // Initialize the usage cache file. | 69 // Initialize the usage cache file. |
| 58 FilePath usage_cache_path = file_system_context_->path_manager() | 70 FilePath usage_cache_path = file_system_context_-> |
| 59 ->sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); | 71 sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); |
| 60 FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); | 72 FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); |
| 61 } | 73 } |
| 62 | 74 |
| 63 void FileSystemTestOriginHelper::SetUp( | 75 void FileSystemTestOriginHelper::SetUp( |
| 64 const FilePath& base_dir, | 76 const FilePath& base_dir, |
| 65 bool incognito_mode, | 77 bool incognito_mode, |
| 66 bool unlimited_quota, | 78 bool unlimited_quota, |
| 67 quota::QuotaManagerProxy* quota_manager_proxy, | 79 quota::QuotaManagerProxy* quota_manager_proxy, |
| 68 FileSystemFileUtil* file_util) { | 80 FileSystemFileUtil* file_util) { |
| 69 file_util_ = file_util; | 81 file_util_ = file_util; |
| 70 DCHECK(file_util_); | 82 DCHECK(file_util_); |
| 71 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = | 83 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = |
| 72 new quota::MockSpecialStoragePolicy; | 84 new quota::MockSpecialStoragePolicy; |
| 73 special_storage_policy->SetAllUnlimited(unlimited_quota); | 85 special_storage_policy->SetAllUnlimited(unlimited_quota); |
| 74 file_system_context_ = new FileSystemContext( | 86 file_system_context_ = new FileSystemContext( |
| 75 base::MessageLoopProxy::current(), | 87 base::MessageLoopProxy::current(), |
| 76 base::MessageLoopProxy::current(), | 88 base::MessageLoopProxy::current(), |
| 77 special_storage_policy, | 89 special_storage_policy, |
| 78 quota_manager_proxy, | 90 quota_manager_proxy, |
| 79 base_dir, | 91 base_dir, |
| 80 incognito_mode, | 92 new TestHelperOptions(incognito_mode)); |
| 81 true /* allow_file_access_from_files */, | |
| 82 NULL); | |
| 83 | 93 |
| 84 DCHECK(file_system_context_->path_manager()); | 94 DCHECK(file_system_context_->sandbox_provider()); |
| 85 DCHECK(file_system_context_->path_manager()->sandbox_provider()); | |
| 86 | 95 |
| 87 // Prepare the origin's root directory. | 96 // Prepare the origin's root directory. |
| 88 file_system_context_->path_manager()-> | 97 file_system_context_->GetMountPointProvider(type_)-> |
| 89 ValidateFileSystemRootAndGetPathOnFileThread( | 98 ValidateFileSystemRootAndGetPathOnFileThread( |
| 90 origin_, type_, FilePath(), true /* create */); | 99 origin_, type_, FilePath(), true /* create */); |
| 91 | 100 |
| 92 // Initialize the usage cache file. This code assumes that we're either using | 101 // Initialize the usage cache file. This code assumes that we're either using |
| 93 // OFSFU or we've mocked it out in the sandbox provider. | 102 // OFSFU or we've mocked it out in the sandbox provider. |
| 94 FilePath usage_cache_path = file_system_context_->path_manager() | 103 FilePath usage_cache_path = file_system_context_-> |
| 95 ->sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); | 104 sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); |
| 96 FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); | 105 FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); |
| 97 } | 106 } |
| 98 | 107 |
| 99 void FileSystemTestOriginHelper::TearDown() { | 108 void FileSystemTestOriginHelper::TearDown() { |
| 100 file_system_context_ = NULL; | 109 file_system_context_ = NULL; |
| 101 MessageLoop::current()->RunAllPending(); | 110 MessageLoop::current()->RunAllPending(); |
| 102 } | 111 } |
| 103 | 112 |
| 104 FilePath FileSystemTestOriginHelper::GetOriginRootPath() const { | 113 FilePath FileSystemTestOriginHelper::GetOriginRootPath() const { |
| 105 return file_system_context_->path_manager()-> | 114 return file_system_context_->GetMountPointProvider(type_)-> |
| 106 ValidateFileSystemRootAndGetPathOnFileThread( | 115 ValidateFileSystemRootAndGetPathOnFileThread( |
| 107 origin_, type_, FilePath(), false); | 116 origin_, type_, FilePath(), false); |
| 108 } | 117 } |
| 109 | 118 |
| 110 FilePath FileSystemTestOriginHelper::GetLocalPath(const FilePath& path) { | 119 FilePath FileSystemTestOriginHelper::GetLocalPath(const FilePath& path) { |
| 111 DCHECK(file_util_); | 120 DCHECK(file_util_); |
| 112 FilePath local_path; | 121 FilePath local_path; |
| 113 scoped_ptr<FileSystemOperationContext> context(NewOperationContext()); | 122 scoped_ptr<FileSystemOperationContext> context(NewOperationContext()); |
| 114 file_util_->GetLocalFilePath(context.get(), path, &local_path); | 123 file_util_->GetLocalFilePath(context.get(), path, &local_path); |
| 115 return local_path; | 124 return local_path; |
| 116 } | 125 } |
| 117 | 126 |
| 118 FilePath FileSystemTestOriginHelper::GetLocalPathFromASCII( | 127 FilePath FileSystemTestOriginHelper::GetLocalPathFromASCII( |
| 119 const std::string& path) { | 128 const std::string& path) { |
| 120 return GetLocalPath(FilePath().AppendASCII(path)); | 129 return GetLocalPath(FilePath().AppendASCII(path)); |
| 121 } | 130 } |
| 122 | 131 |
| 123 GURL FileSystemTestOriginHelper::GetURLForPath(const FilePath& path) const { | 132 GURL FileSystemTestOriginHelper::GetURLForPath(const FilePath& path) const { |
| 124 return GURL(GetFileSystemRootURI(origin_, type_).spec() + | 133 return GURL(GetFileSystemRootURI(origin_, type_).spec() + |
| 125 path.MaybeAsASCII()); | 134 path.MaybeAsASCII()); |
| 126 } | 135 } |
| 127 | 136 |
| 128 FilePath FileSystemTestOriginHelper::GetUsageCachePath() const { | 137 FilePath FileSystemTestOriginHelper::GetUsageCachePath() const { |
| 129 return file_system_context_->path_manager() | 138 return file_system_context_-> |
| 130 ->sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); | 139 sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); |
| 131 } | 140 } |
| 132 | 141 |
| 133 int64 FileSystemTestOriginHelper::GetCachedOriginUsage() const { | 142 int64 FileSystemTestOriginHelper::GetCachedOriginUsage() const { |
| 134 return FileSystemUsageCache::GetUsage(GetUsageCachePath()); | 143 return FileSystemUsageCache::GetUsage(GetUsageCachePath()); |
| 135 } | 144 } |
| 136 | 145 |
| 137 bool FileSystemTestOriginHelper::RevokeUsageCache() const { | 146 bool FileSystemTestOriginHelper::RevokeUsageCache() const { |
| 138 return file_util::Delete(GetUsageCachePath(), false); | 147 return file_util::Delete(GetUsageCachePath(), false); |
| 139 } | 148 } |
| 140 | 149 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 170 void FileSystemTestOriginHelper::InitializeOperationContext( | 179 void FileSystemTestOriginHelper::InitializeOperationContext( |
| 171 FileSystemOperationContext* context) { | 180 FileSystemOperationContext* context) { |
| 172 DCHECK(context); | 181 DCHECK(context); |
| 173 context->set_src_origin_url(origin_); | 182 context->set_src_origin_url(origin_); |
| 174 context->set_src_type(type_); | 183 context->set_src_type(type_); |
| 175 context->set_dest_origin_url(origin_); | 184 context->set_dest_origin_url(origin_); |
| 176 context->set_dest_type(type_); | 185 context->set_dest_type(type_); |
| 177 } | 186 } |
| 178 | 187 |
| 179 } // namespace fileapi | 188 } // namespace fileapi |
| OLD | NEW |