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_operation.h" | 5 #include "webkit/fileapi/local_file_system_operation.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "webkit/blob/shareable_file_reference.h" | 16 #include "webkit/blob/shareable_file_reference.h" |
| 17 #include "webkit/fileapi/async_file_test_helper.h" |
17 #include "webkit/fileapi/file_system_context.h" | 18 #include "webkit/fileapi/file_system_context.h" |
18 #include "webkit/fileapi/file_system_file_util.h" | 19 #include "webkit/fileapi/file_system_file_util.h" |
19 #include "webkit/fileapi/file_system_mount_point_provider.h" | 20 #include "webkit/fileapi/file_system_mount_point_provider.h" |
20 #include "webkit/fileapi/file_system_quota_util.h" | 21 #include "webkit/fileapi/file_system_quota_util.h" |
21 #include "webkit/fileapi/file_system_util.h" | 22 #include "webkit/fileapi/file_system_util.h" |
22 #include "webkit/fileapi/file_util_helper.h" | |
23 #include "webkit/fileapi/local_file_system_test_helper.h" | 23 #include "webkit/fileapi/local_file_system_test_helper.h" |
24 #include "webkit/fileapi/mock_file_change_observer.h" | 24 #include "webkit/fileapi/mock_file_change_observer.h" |
25 #include "webkit/quota/mock_quota_manager.h" | 25 #include "webkit/quota/mock_quota_manager.h" |
26 #include "webkit/quota/quota_manager.h" | 26 #include "webkit/quota/quota_manager.h" |
27 | 27 |
28 using quota::QuotaManager; | 28 using quota::QuotaManager; |
29 using quota::QuotaManagerProxy; | 29 using quota::QuotaManagerProxy; |
30 using webkit_blob::ShareableFileReference; | 30 using webkit_blob::ShareableFileReference; |
31 | 31 |
32 namespace fileapi { | 32 namespace fileapi { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 FileSystemURL URLForPath(const base::FilePath& path) const { | 104 FileSystemURL URLForPath(const base::FilePath& path) const { |
105 return test_helper_.CreateURL(path); | 105 return test_helper_.CreateURL(path); |
106 } | 106 } |
107 | 107 |
108 base::FilePath PlatformPath(const base::FilePath& virtual_path) { | 108 base::FilePath PlatformPath(const base::FilePath& virtual_path) { |
109 return test_helper_.GetLocalPath(virtual_path); | 109 return test_helper_.GetLocalPath(virtual_path); |
110 } | 110 } |
111 | 111 |
112 bool FileExists(const base::FilePath& virtual_path) { | 112 bool FileExists(const base::FilePath& virtual_path) { |
113 FileSystemURL url = test_helper_.CreateURL(virtual_path); | 113 FileSystemURL url = test_helper_.CreateURL(virtual_path); |
114 base::PlatformFileInfo file_info; | 114 return AsyncFileTestHelper::FileExists( |
115 base::FilePath platform_path; | 115 test_helper_.file_system_context(), url, |
116 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 116 AsyncFileTestHelper::kDontCheckSize); |
117 base::PlatformFileError error = file_util()->GetFileInfo( | |
118 context.get(), url, &file_info, &platform_path); | |
119 return error == base::PLATFORM_FILE_OK && !file_info.is_directory; | |
120 } | 117 } |
121 | 118 |
122 bool DirectoryExists(const base::FilePath& virtual_path) { | 119 bool DirectoryExists(const base::FilePath& virtual_path) { |
123 FileSystemURL url = test_helper_.CreateURL(virtual_path); | 120 FileSystemURL url = test_helper_.CreateURL(virtual_path); |
124 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 121 return AsyncFileTestHelper::DirectoryExists( |
125 return FileUtilHelper::DirectoryExists(context.get(), file_util(), url); | 122 test_helper_.file_system_context(), url); |
126 } | 123 } |
127 | 124 |
128 base::FilePath CreateUniqueFileInDir(const base::FilePath& virtual_dir_path) { | 125 base::FilePath CreateUniqueFileInDir(const base::FilePath& virtual_dir_path) { |
129 base::FilePath file_name = base::FilePath::FromUTF8Unsafe( | 126 base::FilePath file_name = base::FilePath::FromUTF8Unsafe( |
130 "tmpfile-" + base::IntToString(next_unique_path_suffix_++)); | 127 "tmpfile-" + base::IntToString(next_unique_path_suffix_++)); |
131 FileSystemURL url = test_helper_.CreateURL( | 128 FileSystemURL url = test_helper_.CreateURL( |
132 virtual_dir_path.Append(file_name)); | 129 virtual_dir_path.Append(file_name)); |
133 | 130 |
134 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 131 scoped_ptr<FileSystemOperationContext> context(NewContext()); |
135 bool created; | 132 bool created; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 base::PlatformFileError status, | 199 base::PlatformFileError status, |
203 const base::PlatformFileInfo& info, | 200 const base::PlatformFileInfo& info, |
204 const base::FilePath& platform_path, | 201 const base::FilePath& platform_path, |
205 const scoped_refptr<ShareableFileReference>& shareable_file_ref) { | 202 const scoped_refptr<ShareableFileReference>& shareable_file_ref) { |
206 info_ = info; | 203 info_ = info; |
207 path_ = platform_path; | 204 path_ = platform_path; |
208 status_ = status; | 205 status_ = status; |
209 shareable_file_ref_ = shareable_file_ref; | 206 shareable_file_ref_ = shareable_file_ref; |
210 } | 207 } |
211 | 208 |
212 static void DidGetUsageAndQuota(quota::QuotaStatusCode* status_out, | |
213 int64* usage_out, | |
214 int64* quota_out, | |
215 quota::QuotaStatusCode status, | |
216 int64 usage, | |
217 int64 quota) { | |
218 if (status_out) | |
219 *status_out = status; | |
220 | |
221 if (usage_out) | |
222 *usage_out = usage; | |
223 | |
224 if (quota_out) | |
225 *quota_out = quota; | |
226 } | |
227 | |
228 void GetUsageAndQuota(int64* usage, int64* quota) { | 209 void GetUsageAndQuota(int64* usage, int64* quota) { |
229 quota::QuotaStatusCode status = quota::kQuotaStatusUnknown; | 210 quota::QuotaStatusCode status = |
230 quota_manager_->GetUsageAndQuota( | 211 AsyncFileTestHelper::GetUsageAndQuota( |
231 test_helper_.origin(), | 212 quota_manager_, test_helper_.origin(), test_helper_.type(), |
232 test_helper_.storage_type(), | 213 usage, quota); |
233 base::Bind(&LocalFileSystemOperationTest::DidGetUsageAndQuota, | |
234 &status, usage, quota)); | |
235 MessageLoop::current()->RunUntilIdle(); | 214 MessageLoop::current()->RunUntilIdle(); |
236 ASSERT_EQ(quota::kQuotaStatusOk, status); | 215 ASSERT_EQ(quota::kQuotaStatusOk, status); |
237 } | 216 } |
238 | 217 |
239 void GenerateUniquePathInDir(const base::FilePath& dir, | 218 void GenerateUniquePathInDir(const base::FilePath& dir, |
240 base::FilePath* file_path, | 219 base::FilePath* file_path, |
241 int64* path_cost) { | 220 int64* path_cost) { |
242 int64 base_usage; | 221 int64 base_usage; |
243 GetUsageAndQuota(&base_usage, NULL); | 222 GetUsageAndQuota(&base_usage, NULL); |
244 *file_path = CreateUniqueFileInDir(dir); | 223 *file_path = CreateUniqueFileInDir(dir); |
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 EXPECT_FALSE(info().is_directory); | 1184 EXPECT_FALSE(info().is_directory); |
1206 EXPECT_EQ(PlatformPath(file_path), path()); | 1185 EXPECT_EQ(PlatformPath(file_path), path()); |
1207 EXPECT_TRUE(change_observer()->HasNoChange()); | 1186 EXPECT_TRUE(change_observer()->HasNoChange()); |
1208 | 1187 |
1209 // The FileSystemOpration implementation does not create a | 1188 // The FileSystemOpration implementation does not create a |
1210 // shareable file reference. | 1189 // shareable file reference. |
1211 EXPECT_EQ(NULL, shareable_file_ref()); | 1190 EXPECT_EQ(NULL, shareable_file_ref()); |
1212 } | 1191 } |
1213 | 1192 |
1214 } // namespace fileapi | 1193 } // namespace fileapi |
OLD | NEW |