OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "content/public/test/async_file_test_helper.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "webkit/browser/fileapi/async_file_test_helper.h" | |
11 #include "webkit/browser/fileapi/file_system_backend.h" | 11 #include "webkit/browser/fileapi/file_system_backend.h" |
12 #include "webkit/browser/fileapi/file_system_context.h" | 12 #include "webkit/browser/fileapi/file_system_context.h" |
13 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 13 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
14 #include "webkit/browser/fileapi/file_system_url.h" | 14 #include "webkit/browser/fileapi/file_system_url.h" |
15 #include "webkit/browser/quota/quota_manager.h" | 15 #include "webkit/browser/quota/quota_manager.h" |
16 #include "webkit/common/fileapi/file_system_util.h" | 16 #include "webkit/common/fileapi/file_system_util.h" |
17 | 17 |
18 namespace fileapi { | 18 namespace content { |
19 | 19 |
20 namespace { | 20 typedef fileapi::FileSystemOperation::FileEntryList FileEntryList; |
21 | |
22 typedef FileSystemOperation::FileEntryList FileEntryList; | |
23 | 21 |
24 void AssignAndQuit(base::RunLoop* run_loop, | 22 void AssignAndQuit(base::RunLoop* run_loop, |
25 base::File::Error* result_out, | 23 base::File::Error* result_out, |
26 base::File::Error result) { | 24 base::File::Error result) { |
27 *result_out = result; | 25 *result_out = result; |
28 run_loop->Quit(); | 26 run_loop->Quit(); |
29 } | 27 } |
30 | 28 |
31 base::Callback<void(base::File::Error)> | 29 base::Callback<void(base::File::Error)> |
32 AssignAndQuitCallback(base::RunLoop* run_loop, | 30 AssignAndQuitCallback(base::RunLoop* run_loop, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 int64 usage, | 77 int64 usage, |
80 int64 quota) { | 78 int64 quota) { |
81 if (status_out) | 79 if (status_out) |
82 *status_out = status; | 80 *status_out = status; |
83 if (usage_out) | 81 if (usage_out) |
84 *usage_out = usage; | 82 *usage_out = usage; |
85 if (quota_out) | 83 if (quota_out) |
86 *quota_out = quota; | 84 *quota_out = quota; |
87 } | 85 } |
88 | 86 |
89 } // namespace | |
90 | |
91 const int64 AsyncFileTestHelper::kDontCheckSize = -1; | 87 const int64 AsyncFileTestHelper::kDontCheckSize = -1; |
92 | 88 |
93 base::File::Error AsyncFileTestHelper::Copy( | 89 base::File::Error AsyncFileTestHelper::Copy( |
94 FileSystemContext* context, | 90 fileapi::FileSystemContext* context, |
95 const FileSystemURL& src, | 91 const fileapi::FileSystemURL& src, |
96 const FileSystemURL& dest) { | 92 const fileapi::FileSystemURL& dest) { |
97 return CopyWithProgress(context, src, dest, CopyProgressCallback()); | 93 return CopyWithProgress(context, src, dest, CopyProgressCallback()); |
98 } | 94 } |
99 | 95 |
100 base::File::Error AsyncFileTestHelper::CopyWithProgress( | 96 base::File::Error AsyncFileTestHelper::CopyWithProgress( |
101 FileSystemContext* context, | 97 fileapi::FileSystemContext* context, |
102 const FileSystemURL& src, | 98 const fileapi::FileSystemURL& src, |
103 const FileSystemURL& dest, | 99 const fileapi::FileSystemURL& dest, |
104 const CopyProgressCallback& progress_callback) { | 100 const CopyProgressCallback& progress_callback) { |
105 base::File::Error result = base::File::FILE_ERROR_FAILED; | 101 base::File::Error result = base::File::FILE_ERROR_FAILED; |
106 base::RunLoop run_loop; | 102 base::RunLoop run_loop; |
107 context->operation_runner()->Copy( | 103 context->operation_runner()->Copy( |
108 src, dest, FileSystemOperation::OPTION_NONE, progress_callback, | 104 src, dest, fileapi::FileSystemOperation::OPTION_NONE, progress_callback, |
109 AssignAndQuitCallback(&run_loop, &result)); | 105 AssignAndQuitCallback(&run_loop, &result)); |
110 run_loop.Run(); | 106 run_loop.Run(); |
111 return result; | 107 return result; |
112 } | 108 } |
113 | 109 |
114 base::File::Error AsyncFileTestHelper::Move( | 110 base::File::Error AsyncFileTestHelper::Move( |
115 FileSystemContext* context, | 111 fileapi::FileSystemContext* context, |
116 const FileSystemURL& src, | 112 const fileapi::FileSystemURL& src, |
117 const FileSystemURL& dest) { | 113 const fileapi::FileSystemURL& dest) { |
118 base::File::Error result = base::File::FILE_ERROR_FAILED; | 114 base::File::Error result = base::File::FILE_ERROR_FAILED; |
119 base::RunLoop run_loop; | 115 base::RunLoop run_loop; |
120 context->operation_runner()->Move( | 116 context->operation_runner()->Move( |
121 src, dest, FileSystemOperation::OPTION_NONE, | 117 src, dest, fileapi::FileSystemOperation::OPTION_NONE, |
122 AssignAndQuitCallback(&run_loop, &result)); | 118 AssignAndQuitCallback(&run_loop, &result)); |
123 run_loop.Run(); | 119 run_loop.Run(); |
124 return result; | 120 return result; |
125 } | 121 } |
126 | 122 |
127 base::File::Error AsyncFileTestHelper::Remove( | 123 base::File::Error AsyncFileTestHelper::Remove( |
128 FileSystemContext* context, | 124 fileapi::FileSystemContext* context, |
129 const FileSystemURL& url, | 125 const fileapi::FileSystemURL& url, |
130 bool recursive) { | 126 bool recursive) { |
131 base::File::Error result = base::File::FILE_ERROR_FAILED; | 127 base::File::Error result = base::File::FILE_ERROR_FAILED; |
132 base::RunLoop run_loop; | 128 base::RunLoop run_loop; |
133 context->operation_runner()->Remove( | 129 context->operation_runner()->Remove( |
134 url, recursive, AssignAndQuitCallback(&run_loop, &result)); | 130 url, recursive, AssignAndQuitCallback(&run_loop, &result)); |
135 run_loop.Run(); | 131 run_loop.Run(); |
136 return result; | 132 return result; |
137 } | 133 } |
138 | 134 |
139 base::File::Error AsyncFileTestHelper::ReadDirectory( | 135 base::File::Error AsyncFileTestHelper::ReadDirectory( |
140 FileSystemContext* context, | 136 fileapi::FileSystemContext* context, |
141 const FileSystemURL& url, | 137 const fileapi::FileSystemURL& url, |
142 FileEntryList* entries) { | 138 FileEntryList* entries) { |
143 base::File::Error result = base::File::FILE_ERROR_FAILED; | 139 base::File::Error result = base::File::FILE_ERROR_FAILED; |
144 DCHECK(entries); | 140 DCHECK(entries); |
145 entries->clear(); | 141 entries->clear(); |
146 base::RunLoop run_loop; | 142 base::RunLoop run_loop; |
147 context->operation_runner()->ReadDirectory( | 143 context->operation_runner()->ReadDirectory( |
148 url, base::Bind(&ReadDirectoryCallback, &run_loop, &result, entries)); | 144 url, base::Bind(&ReadDirectoryCallback, &run_loop, &result, entries)); |
149 run_loop.Run(); | 145 run_loop.Run(); |
150 return result; | 146 return result; |
151 } | 147 } |
152 | 148 |
153 base::File::Error AsyncFileTestHelper::CreateDirectory( | 149 base::File::Error AsyncFileTestHelper::CreateDirectory( |
154 FileSystemContext* context, | 150 fileapi::FileSystemContext* context, |
155 const FileSystemURL& url) { | 151 const fileapi::FileSystemURL& url) { |
156 base::File::Error result = base::File::FILE_ERROR_FAILED; | 152 base::File::Error result = base::File::FILE_ERROR_FAILED; |
157 base::RunLoop run_loop; | 153 base::RunLoop run_loop; |
158 context->operation_runner()->CreateDirectory( | 154 context->operation_runner()->CreateDirectory( |
159 url, | 155 url, |
160 false /* exclusive */, | 156 false /* exclusive */, |
161 false /* recursive */, | 157 false /* recursive */, |
162 AssignAndQuitCallback(&run_loop, &result)); | 158 AssignAndQuitCallback(&run_loop, &result)); |
163 run_loop.Run(); | 159 run_loop.Run(); |
164 return result; | 160 return result; |
165 } | 161 } |
166 | 162 |
167 base::File::Error AsyncFileTestHelper::CreateFile( | 163 base::File::Error AsyncFileTestHelper::CreateFile( |
168 FileSystemContext* context, | 164 fileapi::FileSystemContext* context, |
169 const FileSystemURL& url) { | 165 const fileapi::FileSystemURL& url) { |
170 base::File::Error result = base::File::FILE_ERROR_FAILED; | 166 base::File::Error result = base::File::FILE_ERROR_FAILED; |
171 base::RunLoop run_loop; | 167 base::RunLoop run_loop; |
172 context->operation_runner()->CreateFile( | 168 context->operation_runner()->CreateFile( |
173 url, false /* exclusive */, | 169 url, false /* exclusive */, |
174 AssignAndQuitCallback(&run_loop, &result)); | 170 AssignAndQuitCallback(&run_loop, &result)); |
175 run_loop.Run(); | 171 run_loop.Run(); |
176 return result; | 172 return result; |
177 } | 173 } |
178 | 174 |
179 base::File::Error AsyncFileTestHelper::CreateFileWithData( | 175 base::File::Error AsyncFileTestHelper::CreateFileWithData( |
180 FileSystemContext* context, | 176 fileapi::FileSystemContext* context, |
181 const FileSystemURL& url, | 177 const fileapi::FileSystemURL& url, |
182 const char* buf, | 178 const char* buf, |
183 int buf_size) { | 179 int buf_size) { |
184 base::ScopedTempDir dir; | 180 base::ScopedTempDir dir; |
185 if (!dir.CreateUniqueTempDir()) | 181 if (!dir.CreateUniqueTempDir()) |
186 return base::File::FILE_ERROR_FAILED; | 182 return base::File::FILE_ERROR_FAILED; |
187 base::FilePath local_path = dir.path().AppendASCII("tmp"); | 183 base::FilePath local_path = dir.path().AppendASCII("tmp"); |
188 if (buf_size != file_util::WriteFile(local_path, buf, buf_size)) | 184 if (buf_size != file_util::WriteFile(local_path, buf, buf_size)) |
189 return base::File::FILE_ERROR_FAILED; | 185 return base::File::FILE_ERROR_FAILED; |
190 base::File::Error result = base::File::FILE_ERROR_FAILED; | 186 base::File::Error result = base::File::FILE_ERROR_FAILED; |
191 base::RunLoop run_loop; | 187 base::RunLoop run_loop; |
192 context->operation_runner()->CopyInForeignFile( | 188 context->operation_runner()->CopyInForeignFile( |
193 local_path, url, AssignAndQuitCallback(&run_loop, &result)); | 189 local_path, url, AssignAndQuitCallback(&run_loop, &result)); |
194 run_loop.Run(); | 190 run_loop.Run(); |
195 return result; | 191 return result; |
196 } | 192 } |
197 | 193 |
198 base::File::Error AsyncFileTestHelper::TruncateFile( | 194 base::File::Error AsyncFileTestHelper::TruncateFile( |
199 FileSystemContext* context, | 195 fileapi::FileSystemContext* context, |
200 const FileSystemURL& url, | 196 const fileapi::FileSystemURL& url, |
201 size_t size) { | 197 size_t size) { |
202 base::RunLoop run_loop; | 198 base::RunLoop run_loop; |
203 base::File::Error result = base::File::FILE_ERROR_FAILED; | 199 base::File::Error result = base::File::FILE_ERROR_FAILED; |
204 context->operation_runner()->Truncate( | 200 context->operation_runner()->Truncate( |
205 url, size, AssignAndQuitCallback(&run_loop, &result)); | 201 url, size, AssignAndQuitCallback(&run_loop, &result)); |
206 run_loop.Run(); | 202 run_loop.Run(); |
207 return result; | 203 return result; |
208 } | 204 } |
209 | 205 |
210 base::File::Error AsyncFileTestHelper::GetMetadata( | 206 base::File::Error AsyncFileTestHelper::GetMetadata( |
211 FileSystemContext* context, | 207 fileapi::FileSystemContext* context, |
212 const FileSystemURL& url, | 208 const fileapi::FileSystemURL& url, |
213 base::File::Info* file_info) { | 209 base::File::Info* file_info) { |
214 base::File::Error result = base::File::FILE_ERROR_FAILED; | 210 base::File::Error result = base::File::FILE_ERROR_FAILED; |
215 base::RunLoop run_loop; | 211 base::RunLoop run_loop; |
216 context->operation_runner()->GetMetadata( | 212 context->operation_runner()->GetMetadata( |
217 url, base::Bind(&GetMetadataCallback, &run_loop, &result, | 213 url, base::Bind(&GetMetadataCallback, &run_loop, &result, |
218 file_info)); | 214 file_info)); |
219 run_loop.Run(); | 215 run_loop.Run(); |
220 return result; | 216 return result; |
221 } | 217 } |
222 | 218 |
223 base::File::Error AsyncFileTestHelper::GetPlatformPath( | 219 base::File::Error AsyncFileTestHelper::GetPlatformPath( |
224 FileSystemContext* context, | 220 fileapi::FileSystemContext* context, |
225 const FileSystemURL& url, | 221 const fileapi::FileSystemURL& url, |
226 base::FilePath* platform_path) { | 222 base::FilePath* platform_path) { |
227 base::File::Error result = base::File::FILE_ERROR_FAILED; | 223 base::File::Error result = base::File::FILE_ERROR_FAILED; |
228 base::RunLoop run_loop; | 224 base::RunLoop run_loop; |
229 context->operation_runner()->CreateSnapshotFile( | 225 context->operation_runner()->CreateSnapshotFile( |
230 url, base::Bind(&CreateSnapshotFileCallback, &run_loop, &result, | 226 url, base::Bind(&CreateSnapshotFileCallback, &run_loop, &result, |
231 platform_path)); | 227 platform_path)); |
232 run_loop.Run(); | 228 run_loop.Run(); |
233 return result; | 229 return result; |
234 } | 230 } |
235 | 231 |
236 bool AsyncFileTestHelper::FileExists( | 232 bool AsyncFileTestHelper::FileExists( |
237 FileSystemContext* context, | 233 fileapi::FileSystemContext* context, |
238 const FileSystemURL& url, | 234 const fileapi::FileSystemURL& url, |
239 int64 expected_size) { | 235 int64 expected_size) { |
240 base::File::Info file_info; | 236 base::File::Info file_info; |
241 base::File::Error result = GetMetadata(context, url, &file_info); | 237 base::File::Error result = GetMetadata(context, url, &file_info); |
242 if (result != base::File::FILE_OK || file_info.is_directory) | 238 if (result != base::File::FILE_OK || file_info.is_directory) |
243 return false; | 239 return false; |
244 return expected_size == kDontCheckSize || file_info.size == expected_size; | 240 return expected_size == kDontCheckSize || file_info.size == expected_size; |
245 } | 241 } |
246 | 242 |
247 bool AsyncFileTestHelper::DirectoryExists( | 243 bool AsyncFileTestHelper::DirectoryExists( |
248 FileSystemContext* context, | 244 fileapi::FileSystemContext* context, |
249 const FileSystemURL& url) { | 245 const fileapi::FileSystemURL& url) { |
250 base::File::Info file_info; | 246 base::File::Info file_info; |
251 base::File::Error result = GetMetadata(context, url, &file_info); | 247 base::File::Error result = GetMetadata(context, url, &file_info); |
252 return (result == base::File::FILE_OK) && file_info.is_directory; | 248 return (result == base::File::FILE_OK) && file_info.is_directory; |
253 } | 249 } |
254 | 250 |
255 quota::QuotaStatusCode AsyncFileTestHelper::GetUsageAndQuota( | 251 quota::QuotaStatusCode AsyncFileTestHelper::GetUsageAndQuota( |
256 quota::QuotaManager* quota_manager, | 252 quota::QuotaManager* quota_manager, |
257 const GURL& origin, | 253 const GURL& origin, |
258 FileSystemType type, | 254 fileapi::FileSystemType type, |
259 int64* usage, | 255 int64* usage, |
260 int64* quota) { | 256 int64* quota) { |
261 quota::QuotaStatusCode status = quota::kQuotaStatusUnknown; | 257 quota::QuotaStatusCode status = quota::kQuotaStatusUnknown; |
262 quota_manager->GetUsageAndQuota( | 258 quota_manager->GetUsageAndQuota( |
263 origin, | 259 origin, |
264 FileSystemTypeToQuotaStorageType(type), | 260 FileSystemTypeToQuotaStorageType(type), |
265 base::Bind(&DidGetUsageAndQuota, &status, usage, quota)); | 261 base::Bind(&DidGetUsageAndQuota, &status, usage, quota)); |
266 base::RunLoop().RunUntilIdle(); | 262 base::RunLoop().RunUntilIdle(); |
267 return status; | 263 return status; |
268 } | 264 } |
269 | 265 |
270 } // namespace fileapi | 266 } // namespace fileapi |
OLD | NEW |