| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/local_file_system_test_helper.h" | 5 #include "webkit/fileapi/local_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/external_mount_points.h" | |
| 12 #include "webkit/fileapi/file_system_context.h" | 11 #include "webkit/fileapi/file_system_context.h" |
| 13 #include "webkit/fileapi/file_system_file_util.h" | 12 #include "webkit/fileapi/file_system_file_util.h" |
| 14 #include "webkit/fileapi/file_system_operation_context.h" | 13 #include "webkit/fileapi/file_system_operation_context.h" |
| 15 #include "webkit/fileapi/file_system_task_runners.h" | 14 #include "webkit/fileapi/file_system_task_runners.h" |
| 16 #include "webkit/fileapi/file_system_url.h" | 15 #include "webkit/fileapi/file_system_url.h" |
| 17 #include "webkit/fileapi/file_system_usage_cache.h" | 16 #include "webkit/fileapi/file_system_usage_cache.h" |
| 18 #include "webkit/fileapi/file_system_util.h" | 17 #include "webkit/fileapi/file_system_util.h" |
| 19 #include "webkit/fileapi/local_file_system_operation.h" | 18 #include "webkit/fileapi/local_file_system_operation.h" |
| 20 #include "webkit/fileapi/mock_file_system_options.h" | 19 #include "webkit/fileapi/mock_file_system_context.h" |
| 21 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 20 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 22 #include "webkit/fileapi/test_mount_point_provider.h" | |
| 23 #include "webkit/quota/mock_special_storage_policy.h" | 21 #include "webkit/quota/mock_special_storage_policy.h" |
| 24 | 22 |
| 25 namespace fileapi { | 23 namespace fileapi { |
| 26 | 24 |
| 27 LocalFileSystemTestOriginHelper::LocalFileSystemTestOriginHelper( | 25 LocalFileSystemTestOriginHelper::LocalFileSystemTestOriginHelper( |
| 28 const GURL& origin, FileSystemType type) | 26 const GURL& origin, FileSystemType type) |
| 29 : origin_(origin), type_(type), file_util_(NULL) { | 27 : origin_(origin), type_(type), file_util_(NULL) { |
| 30 } | 28 } |
| 31 | 29 |
| 32 LocalFileSystemTestOriginHelper::LocalFileSystemTestOriginHelper() | 30 LocalFileSystemTestOriginHelper::LocalFileSystemTestOriginHelper() |
| 33 : origin_(GURL("http://foo.com")), | 31 : origin_(GURL("http://foo.com")), |
| 34 type_(kFileSystemTypeTemporary), | 32 type_(kFileSystemTypeTemporary), |
| 35 file_util_(NULL) { | 33 file_util_(NULL) { |
| 36 } | 34 } |
| 37 | 35 |
| 38 LocalFileSystemTestOriginHelper::~LocalFileSystemTestOriginHelper() { | 36 LocalFileSystemTestOriginHelper::~LocalFileSystemTestOriginHelper() { |
| 39 } | 37 } |
| 40 | 38 |
| 41 void LocalFileSystemTestOriginHelper::SetUp(const base::FilePath& base_dir) { | 39 void LocalFileSystemTestOriginHelper::SetUp(const base::FilePath& base_dir) { |
| 42 SetUp(base_dir, false, NULL); | 40 SetUp(base_dir, NULL); |
| 43 } | 41 } |
| 44 | 42 |
| 45 void LocalFileSystemTestOriginHelper::SetUp( | 43 void LocalFileSystemTestOriginHelper::SetUp( |
| 46 FileSystemContext* file_system_context) { | 44 FileSystemContext* file_system_context) { |
| 47 file_system_context_ = file_system_context; | 45 file_system_context_ = file_system_context; |
| 48 | 46 |
| 49 SetUpFileUtil(); | 47 SetUpFileUtil(); |
| 50 | 48 |
| 51 // Prepare the origin's root directory. | 49 // Prepare the origin's root directory. |
| 52 file_system_context_->GetMountPointProvider(type_)-> | 50 file_system_context_->GetMountPointProvider(type_)-> |
| 53 GetFileSystemRootPathOnFileThread(CreateURL(base::FilePath()), | 51 GetFileSystemRootPathOnFileThread(CreateURL(base::FilePath()), |
| 54 true /* create */); | 52 true /* create */); |
| 55 | 53 |
| 56 // Initialize the usage cache file. | 54 // Initialize the usage cache file. |
| 57 base::FilePath usage_cache_path = GetUsageCachePath(); | 55 base::FilePath usage_cache_path = GetUsageCachePath(); |
| 58 if (!usage_cache_path.empty()) | 56 if (!usage_cache_path.empty()) |
| 59 usage_cache()->UpdateUsage(usage_cache_path, 0); | 57 usage_cache()->UpdateUsage(usage_cache_path, 0); |
| 60 } | 58 } |
| 61 | 59 |
| 62 void LocalFileSystemTestOriginHelper::SetUp( | 60 void LocalFileSystemTestOriginHelper::SetUp( |
| 63 const base::FilePath& base_dir, | 61 const base::FilePath& base_dir, |
| 64 bool unlimited_quota, | |
| 65 quota::QuotaManagerProxy* quota_manager_proxy) { | 62 quota::QuotaManagerProxy* quota_manager_proxy) { |
| 66 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = | 63 file_system_context_ = CreateFileSystemContextForTesting( |
| 67 new quota::MockSpecialStoragePolicy; | 64 quota_manager_proxy, base_dir); |
| 68 special_storage_policy->SetAllUnlimited(unlimited_quota); | |
| 69 file_system_context_ = new FileSystemContext( | |
| 70 FileSystemTaskRunners::CreateMockTaskRunners(), | |
| 71 ExternalMountPoints::CreateRefCounted().get(), | |
| 72 special_storage_policy, | |
| 73 quota_manager_proxy, | |
| 74 base_dir, | |
| 75 CreateAllowFileAccessOptions()); | |
| 76 | 65 |
| 77 SetUpFileUtil(); | 66 SetUpFileUtil(); |
| 78 | 67 |
| 79 // Prepare the origin's root directory. | 68 // Prepare the origin's root directory. |
| 80 FileSystemMountPointProvider* mount_point_provider = | 69 FileSystemMountPointProvider* mount_point_provider = |
| 81 file_system_context_->GetMountPointProvider(type_); | 70 file_system_context_->GetMountPointProvider(type_); |
| 82 mount_point_provider->GetFileSystemRootPathOnFileThread( | 71 mount_point_provider->GetFileSystemRootPathOnFileThread( |
| 83 CreateURL(base::FilePath()), true /* create */); | 72 CreateURL(base::FilePath()), true /* create */); |
| 84 | 73 |
| 85 // Initialize the usage cache file. | 74 // Initialize the usage cache file. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 *file_system_context_->GetUpdateObservers(type_)); | 154 *file_system_context_->GetUpdateObservers(type_)); |
| 166 return context; | 155 return context; |
| 167 } | 156 } |
| 168 | 157 |
| 169 FileSystemUsageCache* LocalFileSystemTestOriginHelper::usage_cache() { | 158 FileSystemUsageCache* LocalFileSystemTestOriginHelper::usage_cache() { |
| 170 return file_system_context()->sandbox_provider()->usage_cache(); | 159 return file_system_context()->sandbox_provider()->usage_cache(); |
| 171 } | 160 } |
| 172 | 161 |
| 173 void LocalFileSystemTestOriginHelper::SetUpFileUtil() { | 162 void LocalFileSystemTestOriginHelper::SetUpFileUtil() { |
| 174 DCHECK(file_system_context_); | 163 DCHECK(file_system_context_); |
| 175 if (type_ == kFileSystemTypeTest) { | |
| 176 file_system_context_->RegisterMountPointProvider( | |
| 177 type_, | |
| 178 new TestMountPointProvider( | |
| 179 file_system_context_->task_runners()->file_task_runner(), | |
| 180 file_system_context_->partition_path())); | |
| 181 } | |
| 182 file_util_ = file_system_context_->GetFileUtil(type_); | 164 file_util_ = file_system_context_->GetFileUtil(type_); |
| 183 DCHECK(file_util_); | 165 DCHECK(file_util_); |
| 184 } | 166 } |
| 185 | 167 |
| 186 } // namespace fileapi | 168 } // namespace fileapi |
| OLD | NEW |