| 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_usage_cache.h" | 14 #include "webkit/fileapi/file_system_usage_cache.h" |
| 15 #include "webkit/fileapi/file_system_util.h" | 15 #include "webkit/fileapi/file_system_util.h" |
| 16 #include "webkit/fileapi/mock_file_system_options.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 |
| 21 FileSystemTestOriginHelper::FileSystemTestOriginHelper( | 22 FileSystemTestOriginHelper::FileSystemTestOriginHelper( |
| 22 const GURL& origin, FileSystemType type) | 23 const GURL& origin, FileSystemType type) |
| 23 : origin_(origin), type_(type), file_util_(NULL) { | 24 : origin_(origin), type_(type), file_util_(NULL) { |
| 24 } | 25 } |
| 25 | 26 |
| 26 FileSystemTestOriginHelper::FileSystemTestOriginHelper() | 27 FileSystemTestOriginHelper::FileSystemTestOriginHelper() |
| 27 : origin_(GURL("http://foo.com")), | 28 : origin_(GURL("http://foo.com")), |
| 28 type_(kFileSystemTypeTemporary), | 29 type_(kFileSystemTypeTemporary), |
| 29 file_util_(NULL) { | 30 file_util_(NULL) { |
| 30 } | 31 } |
| 31 | 32 |
| 32 FileSystemTestOriginHelper::~FileSystemTestOriginHelper() { | 33 FileSystemTestOriginHelper::~FileSystemTestOriginHelper() { |
| 33 } | 34 } |
| 34 | 35 |
| 35 void FileSystemTestOriginHelper::SetUp( | 36 void FileSystemTestOriginHelper::SetUp( |
| 36 const FilePath& base_dir, FileSystemFileUtil* file_util) { | 37 const FilePath& base_dir, FileSystemFileUtil* file_util) { |
| 37 SetUp(base_dir, false, false, NULL, file_util); | 38 SetUp(base_dir, false, NULL, file_util); |
| 38 } | 39 } |
| 39 | 40 |
| 40 void FileSystemTestOriginHelper::SetUp( | 41 void FileSystemTestOriginHelper::SetUp( |
| 41 FileSystemContext* file_system_context, FileSystemFileUtil* file_util) { | 42 FileSystemContext* file_system_context, FileSystemFileUtil* file_util) { |
| 42 DCHECK(file_system_context->path_manager()); | 43 DCHECK(file_system_context->sandbox_provider()); |
| 43 DCHECK(file_system_context->path_manager()->sandbox_provider()); | |
| 44 | 44 |
| 45 file_util_ = file_util; | 45 file_util_ = file_util; |
| 46 file_system_context_ = file_system_context; | 46 file_system_context_ = file_system_context; |
| 47 if (!file_util_) | 47 if (!file_util_) |
| 48 file_util_ = file_system_context->path_manager()->sandbox_provider()-> | 48 file_util_ = file_system_context->sandbox_provider()->GetFileUtil(); |
| 49 GetFileUtil(); | |
| 50 DCHECK(file_util_); | 49 DCHECK(file_util_); |
| 51 | 50 |
| 52 // Prepare the origin's root directory. | 51 // Prepare the origin's root directory. |
| 53 file_system_context_->path_manager()-> | 52 file_system_context_->GetMountPointProvider(type_)-> |
| 54 ValidateFileSystemRootAndGetPathOnFileThread( | 53 ValidateFileSystemRootAndGetPathOnFileThread( |
| 55 origin_, type_, FilePath(), true /* create */); | 54 origin_, type_, FilePath(), true /* create */); |
| 56 | 55 |
| 57 // Initialize the usage cache file. | 56 // Initialize the usage cache file. |
| 58 FilePath usage_cache_path = file_system_context_->path_manager() | 57 FilePath usage_cache_path = file_system_context_-> |
| 59 ->sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); | 58 sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); |
| 60 FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); | 59 FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); |
| 61 } | 60 } |
| 62 | 61 |
| 63 void FileSystemTestOriginHelper::SetUp( | 62 void FileSystemTestOriginHelper::SetUp( |
| 64 const FilePath& base_dir, | 63 const FilePath& base_dir, |
| 65 bool incognito_mode, | |
| 66 bool unlimited_quota, | 64 bool unlimited_quota, |
| 67 quota::QuotaManagerProxy* quota_manager_proxy, | 65 quota::QuotaManagerProxy* quota_manager_proxy, |
| 68 FileSystemFileUtil* file_util) { | 66 FileSystemFileUtil* file_util) { |
| 69 file_util_ = file_util; | 67 file_util_ = file_util; |
| 70 DCHECK(file_util_); | 68 DCHECK(file_util_); |
| 71 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = | 69 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = |
| 72 new quota::MockSpecialStoragePolicy; | 70 new quota::MockSpecialStoragePolicy; |
| 73 special_storage_policy->SetAllUnlimited(unlimited_quota); | 71 special_storage_policy->SetAllUnlimited(unlimited_quota); |
| 74 file_system_context_ = new FileSystemContext( | 72 file_system_context_ = new FileSystemContext( |
| 75 base::MessageLoopProxy::current(), | 73 base::MessageLoopProxy::current(), |
| 76 base::MessageLoopProxy::current(), | 74 base::MessageLoopProxy::current(), |
| 77 special_storage_policy, | 75 special_storage_policy, |
| 78 quota_manager_proxy, | 76 quota_manager_proxy, |
| 79 base_dir, | 77 base_dir, |
| 80 incognito_mode, | 78 CreateAllowFileAccessOptions()); |
| 81 true /* allow_file_access_from_files */, | |
| 82 NULL); | |
| 83 | 79 |
| 84 DCHECK(file_system_context_->path_manager()); | 80 DCHECK(file_system_context_->sandbox_provider()); |
| 85 DCHECK(file_system_context_->path_manager()->sandbox_provider()); | |
| 86 | 81 |
| 87 // Prepare the origin's root directory. | 82 // Prepare the origin's root directory. |
| 88 file_system_context_->path_manager()-> | 83 file_system_context_->GetMountPointProvider(type_)-> |
| 89 ValidateFileSystemRootAndGetPathOnFileThread( | 84 ValidateFileSystemRootAndGetPathOnFileThread( |
| 90 origin_, type_, FilePath(), true /* create */); | 85 origin_, type_, FilePath(), true /* create */); |
| 91 | 86 |
| 92 // Initialize the usage cache file. This code assumes that we're either using | 87 // 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. | 88 // OFSFU or we've mocked it out in the sandbox provider. |
| 94 FilePath usage_cache_path = file_system_context_->path_manager() | 89 FilePath usage_cache_path = file_system_context_-> |
| 95 ->sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); | 90 sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); |
| 96 FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); | 91 FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); |
| 97 } | 92 } |
| 98 | 93 |
| 99 void FileSystemTestOriginHelper::TearDown() { | 94 void FileSystemTestOriginHelper::TearDown() { |
| 100 file_system_context_ = NULL; | 95 file_system_context_ = NULL; |
| 101 MessageLoop::current()->RunAllPending(); | 96 MessageLoop::current()->RunAllPending(); |
| 102 } | 97 } |
| 103 | 98 |
| 104 FilePath FileSystemTestOriginHelper::GetOriginRootPath() const { | 99 FilePath FileSystemTestOriginHelper::GetOriginRootPath() const { |
| 105 return file_system_context_->path_manager()-> | 100 return file_system_context_->GetMountPointProvider(type_)-> |
| 106 ValidateFileSystemRootAndGetPathOnFileThread( | 101 ValidateFileSystemRootAndGetPathOnFileThread( |
| 107 origin_, type_, FilePath(), false); | 102 origin_, type_, FilePath(), false); |
| 108 } | 103 } |
| 109 | 104 |
| 110 FilePath FileSystemTestOriginHelper::GetLocalPath(const FilePath& path) { | 105 FilePath FileSystemTestOriginHelper::GetLocalPath(const FilePath& path) { |
| 111 DCHECK(file_util_); | 106 DCHECK(file_util_); |
| 112 FilePath local_path; | 107 FilePath local_path; |
| 113 scoped_ptr<FileSystemOperationContext> context(NewOperationContext()); | 108 scoped_ptr<FileSystemOperationContext> context(NewOperationContext()); |
| 114 file_util_->GetLocalFilePath(context.get(), path, &local_path); | 109 file_util_->GetLocalFilePath(context.get(), path, &local_path); |
| 115 return local_path; | 110 return local_path; |
| 116 } | 111 } |
| 117 | 112 |
| 118 FilePath FileSystemTestOriginHelper::GetLocalPathFromASCII( | 113 FilePath FileSystemTestOriginHelper::GetLocalPathFromASCII( |
| 119 const std::string& path) { | 114 const std::string& path) { |
| 120 return GetLocalPath(FilePath().AppendASCII(path)); | 115 return GetLocalPath(FilePath().AppendASCII(path)); |
| 121 } | 116 } |
| 122 | 117 |
| 123 GURL FileSystemTestOriginHelper::GetURLForPath(const FilePath& path) const { | 118 GURL FileSystemTestOriginHelper::GetURLForPath(const FilePath& path) const { |
| 124 return GURL(GetFileSystemRootURI(origin_, type_).spec() + | 119 return GURL(GetFileSystemRootURI(origin_, type_).spec() + |
| 125 path.MaybeAsASCII()); | 120 path.MaybeAsASCII()); |
| 126 } | 121 } |
| 127 | 122 |
| 128 FilePath FileSystemTestOriginHelper::GetUsageCachePath() const { | 123 FilePath FileSystemTestOriginHelper::GetUsageCachePath() const { |
| 129 return file_system_context_->path_manager() | 124 return file_system_context_-> |
| 130 ->sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); | 125 sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); |
| 131 } | 126 } |
| 132 | 127 |
| 133 int64 FileSystemTestOriginHelper::GetCachedOriginUsage() const { | 128 int64 FileSystemTestOriginHelper::GetCachedOriginUsage() const { |
| 134 return FileSystemUsageCache::GetUsage(GetUsageCachePath()); | 129 return FileSystemUsageCache::GetUsage(GetUsageCachePath()); |
| 135 } | 130 } |
| 136 | 131 |
| 137 bool FileSystemTestOriginHelper::RevokeUsageCache() const { | 132 bool FileSystemTestOriginHelper::RevokeUsageCache() const { |
| 138 return file_util::Delete(GetUsageCachePath(), false); | 133 return file_util::Delete(GetUsageCachePath(), false); |
| 139 } | 134 } |
| 140 | 135 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 170 void FileSystemTestOriginHelper::InitializeOperationContext( | 165 void FileSystemTestOriginHelper::InitializeOperationContext( |
| 171 FileSystemOperationContext* context) { | 166 FileSystemOperationContext* context) { |
| 172 DCHECK(context); | 167 DCHECK(context); |
| 173 context->set_src_origin_url(origin_); | 168 context->set_src_origin_url(origin_); |
| 174 context->set_src_type(type_); | 169 context->set_src_type(type_); |
| 175 context->set_dest_origin_url(origin_); | 170 context->set_dest_origin_url(origin_); |
| 176 context->set_dest_type(type_); | 171 context->set_dest_type(type_); |
| 177 } | 172 } |
| 178 | 173 |
| 179 } // namespace fileapi | 174 } // namespace fileapi |
| OLD | NEW |