| 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 "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "webkit/browser/fileapi/async_file_test_helper.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 fileapi { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 typedef FileSystemOperation::FileEntryList FileEntryList; | 22 typedef FileSystemOperation::FileEntryList FileEntryList; |
| 23 | 23 |
| 24 void AssignAndQuit(base::RunLoop* run_loop, | 24 void AssignAndQuit(base::RunLoop* run_loop, |
| 25 base::PlatformFileError* result_out, | 25 base::File::Error* result_out, |
| 26 base::PlatformFileError result) { | 26 base::File::Error result) { |
| 27 *result_out = result; | 27 *result_out = result; |
| 28 run_loop->Quit(); | 28 run_loop->Quit(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 base::Callback<void(base::PlatformFileError)> | 31 base::Callback<void(base::File::Error)> |
| 32 AssignAndQuitCallback(base::RunLoop* run_loop, | 32 AssignAndQuitCallback(base::RunLoop* run_loop, |
| 33 base::PlatformFileError* result) { | 33 base::File::Error* result) { |
| 34 return base::Bind(&AssignAndQuit, run_loop, base::Unretained(result)); | 34 return base::Bind(&AssignAndQuit, run_loop, base::Unretained(result)); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void GetMetadataCallback(base::RunLoop* run_loop, | 37 void GetMetadataCallback(base::RunLoop* run_loop, |
| 38 base::PlatformFileError* result_out, | 38 base::File::Error* result_out, |
| 39 base::PlatformFileInfo* file_info_out, | 39 base::File::Info* file_info_out, |
| 40 base::PlatformFileError result, | 40 base::File::Error result, |
| 41 const base::PlatformFileInfo& file_info) { | 41 const base::File::Info& file_info) { |
| 42 *result_out = result; | 42 *result_out = result; |
| 43 if (file_info_out) | 43 if (file_info_out) |
| 44 *file_info_out = file_info; | 44 *file_info_out = file_info; |
| 45 run_loop->Quit(); | 45 run_loop->Quit(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void CreateSnapshotFileCallback( | 48 void CreateSnapshotFileCallback( |
| 49 base::RunLoop* run_loop, | 49 base::RunLoop* run_loop, |
| 50 base::PlatformFileError* result_out, | 50 base::File::Error* result_out, |
| 51 base::FilePath* platform_path_out, | 51 base::FilePath* platform_path_out, |
| 52 base::PlatformFileError result, | 52 base::File::Error result, |
| 53 const base::PlatformFileInfo& file_info, | 53 const base::File::Info& file_info, |
| 54 const base::FilePath& platform_path, | 54 const base::FilePath& platform_path, |
| 55 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 55 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { |
| 56 DCHECK(!file_ref.get()); | 56 DCHECK(!file_ref.get()); |
| 57 *result_out = result; | 57 *result_out = result; |
| 58 if (platform_path_out) | 58 if (platform_path_out) |
| 59 *platform_path_out = platform_path; | 59 *platform_path_out = platform_path; |
| 60 run_loop->Quit(); | 60 run_loop->Quit(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void ReadDirectoryCallback(base::RunLoop* run_loop, | 63 void ReadDirectoryCallback(base::RunLoop* run_loop, |
| 64 base::PlatformFileError* result_out, | 64 base::File::Error* result_out, |
| 65 FileEntryList* entries_out, | 65 FileEntryList* entries_out, |
| 66 base::PlatformFileError result, | 66 base::File::Error result, |
| 67 const FileEntryList& entries, | 67 const FileEntryList& entries, |
| 68 bool has_more) { | 68 bool has_more) { |
| 69 *result_out = result; | 69 *result_out = result; |
| 70 *entries_out = entries; | 70 *entries_out = entries; |
| 71 if (result != base::PLATFORM_FILE_OK || !has_more) | 71 if (result != base::File::FILE_OK || !has_more) |
| 72 run_loop->Quit(); | 72 run_loop->Quit(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void DidGetUsageAndQuota(quota::QuotaStatusCode* status_out, | 75 void DidGetUsageAndQuota(quota::QuotaStatusCode* status_out, |
| 76 int64* usage_out, | 76 int64* usage_out, |
| 77 int64* quota_out, | 77 int64* quota_out, |
| 78 quota::QuotaStatusCode status, | 78 quota::QuotaStatusCode status, |
| 79 int64 usage, | 79 int64 usage, |
| 80 int64 quota) { | 80 int64 quota) { |
| 81 if (status_out) | 81 if (status_out) |
| 82 *status_out = status; | 82 *status_out = status; |
| 83 if (usage_out) | 83 if (usage_out) |
| 84 *usage_out = usage; | 84 *usage_out = usage; |
| 85 if (quota_out) | 85 if (quota_out) |
| 86 *quota_out = quota; | 86 *quota_out = quota; |
| 87 } | 87 } |
| 88 | 88 |
| 89 } // namespace | 89 } // namespace |
| 90 | 90 |
| 91 const int64 AsyncFileTestHelper::kDontCheckSize = -1; | 91 const int64 AsyncFileTestHelper::kDontCheckSize = -1; |
| 92 | 92 |
| 93 base::PlatformFileError AsyncFileTestHelper::Copy( | 93 base::File::Error AsyncFileTestHelper::Copy( |
| 94 FileSystemContext* context, | 94 FileSystemContext* context, |
| 95 const FileSystemURL& src, | 95 const FileSystemURL& src, |
| 96 const FileSystemURL& dest) { | 96 const FileSystemURL& dest) { |
| 97 return CopyWithProgress(context, src, dest, CopyProgressCallback()); | 97 return CopyWithProgress(context, src, dest, CopyProgressCallback()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 base::PlatformFileError AsyncFileTestHelper::CopyWithProgress( | 100 base::File::Error AsyncFileTestHelper::CopyWithProgress( |
| 101 FileSystemContext* context, | 101 FileSystemContext* context, |
| 102 const FileSystemURL& src, | 102 const FileSystemURL& src, |
| 103 const FileSystemURL& dest, | 103 const FileSystemURL& dest, |
| 104 const CopyProgressCallback& progress_callback) { | 104 const CopyProgressCallback& progress_callback) { |
| 105 base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED; | 105 base::File::Error result = base::File::FILE_ERROR_FAILED; |
| 106 base::RunLoop run_loop; | 106 base::RunLoop run_loop; |
| 107 context->operation_runner()->Copy( | 107 context->operation_runner()->Copy( |
| 108 src, dest, FileSystemOperation::OPTION_NONE, progress_callback, | 108 src, dest, FileSystemOperation::OPTION_NONE, progress_callback, |
| 109 AssignAndQuitCallback(&run_loop, &result)); | 109 AssignAndQuitCallback(&run_loop, &result)); |
| 110 run_loop.Run(); | 110 run_loop.Run(); |
| 111 return result; | 111 return result; |
| 112 } | 112 } |
| 113 | 113 |
| 114 base::PlatformFileError AsyncFileTestHelper::Move( | 114 base::File::Error AsyncFileTestHelper::Move( |
| 115 FileSystemContext* context, | 115 FileSystemContext* context, |
| 116 const FileSystemURL& src, | 116 const FileSystemURL& src, |
| 117 const FileSystemURL& dest) { | 117 const FileSystemURL& dest) { |
| 118 base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED; | 118 base::File::Error result = base::File::FILE_ERROR_FAILED; |
| 119 base::RunLoop run_loop; | 119 base::RunLoop run_loop; |
| 120 context->operation_runner()->Move( | 120 context->operation_runner()->Move( |
| 121 src, dest, FileSystemOperation::OPTION_NONE, | 121 src, dest, FileSystemOperation::OPTION_NONE, |
| 122 AssignAndQuitCallback(&run_loop, &result)); | 122 AssignAndQuitCallback(&run_loop, &result)); |
| 123 run_loop.Run(); | 123 run_loop.Run(); |
| 124 return result; | 124 return result; |
| 125 } | 125 } |
| 126 | 126 |
| 127 base::PlatformFileError AsyncFileTestHelper::Remove( | 127 base::File::Error AsyncFileTestHelper::Remove( |
| 128 FileSystemContext* context, | 128 FileSystemContext* context, |
| 129 const FileSystemURL& url, | 129 const FileSystemURL& url, |
| 130 bool recursive) { | 130 bool recursive) { |
| 131 base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED; | 131 base::File::Error result = base::File::FILE_ERROR_FAILED; |
| 132 base::RunLoop run_loop; | 132 base::RunLoop run_loop; |
| 133 context->operation_runner()->Remove( | 133 context->operation_runner()->Remove( |
| 134 url, recursive, AssignAndQuitCallback(&run_loop, &result)); | 134 url, recursive, AssignAndQuitCallback(&run_loop, &result)); |
| 135 run_loop.Run(); | 135 run_loop.Run(); |
| 136 return result; | 136 return result; |
| 137 } | 137 } |
| 138 | 138 |
| 139 base::PlatformFileError AsyncFileTestHelper::ReadDirectory( | 139 base::File::Error AsyncFileTestHelper::ReadDirectory( |
| 140 FileSystemContext* context, | 140 FileSystemContext* context, |
| 141 const FileSystemURL& url, | 141 const FileSystemURL& url, |
| 142 FileEntryList* entries) { | 142 FileEntryList* entries) { |
| 143 base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED; | 143 base::File::Error result = base::File::FILE_ERROR_FAILED; |
| 144 DCHECK(entries); | 144 DCHECK(entries); |
| 145 entries->clear(); | 145 entries->clear(); |
| 146 base::RunLoop run_loop; | 146 base::RunLoop run_loop; |
| 147 context->operation_runner()->ReadDirectory( | 147 context->operation_runner()->ReadDirectory( |
| 148 url, base::Bind(&ReadDirectoryCallback, &run_loop, &result, entries)); | 148 url, base::Bind(&ReadDirectoryCallback, &run_loop, &result, entries)); |
| 149 run_loop.Run(); | 149 run_loop.Run(); |
| 150 return result; | 150 return result; |
| 151 } | 151 } |
| 152 | 152 |
| 153 base::PlatformFileError AsyncFileTestHelper::CreateDirectory( | 153 base::File::Error AsyncFileTestHelper::CreateDirectory( |
| 154 FileSystemContext* context, | 154 FileSystemContext* context, |
| 155 const FileSystemURL& url) { | 155 const FileSystemURL& url) { |
| 156 base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED; | 156 base::File::Error result = base::File::FILE_ERROR_FAILED; |
| 157 base::RunLoop run_loop; | 157 base::RunLoop run_loop; |
| 158 context->operation_runner()->CreateDirectory( | 158 context->operation_runner()->CreateDirectory( |
| 159 url, | 159 url, |
| 160 false /* exclusive */, | 160 false /* exclusive */, |
| 161 false /* recursive */, | 161 false /* recursive */, |
| 162 AssignAndQuitCallback(&run_loop, &result)); | 162 AssignAndQuitCallback(&run_loop, &result)); |
| 163 run_loop.Run(); | 163 run_loop.Run(); |
| 164 return result; | 164 return result; |
| 165 } | 165 } |
| 166 | 166 |
| 167 base::PlatformFileError AsyncFileTestHelper::CreateFile( | 167 base::File::Error AsyncFileTestHelper::CreateFile( |
| 168 FileSystemContext* context, | 168 FileSystemContext* context, |
| 169 const FileSystemURL& url) { | 169 const FileSystemURL& url) { |
| 170 base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED; | 170 base::File::Error result = base::File::FILE_ERROR_FAILED; |
| 171 base::RunLoop run_loop; | 171 base::RunLoop run_loop; |
| 172 context->operation_runner()->CreateFile( | 172 context->operation_runner()->CreateFile( |
| 173 url, false /* exclusive */, | 173 url, false /* exclusive */, |
| 174 AssignAndQuitCallback(&run_loop, &result)); | 174 AssignAndQuitCallback(&run_loop, &result)); |
| 175 run_loop.Run(); | 175 run_loop.Run(); |
| 176 return result; | 176 return result; |
| 177 } | 177 } |
| 178 | 178 |
| 179 base::PlatformFileError AsyncFileTestHelper::CreateFileWithData( | 179 base::File::Error AsyncFileTestHelper::CreateFileWithData( |
| 180 FileSystemContext* context, | 180 FileSystemContext* context, |
| 181 const FileSystemURL& url, | 181 const FileSystemURL& url, |
| 182 const char* buf, | 182 const char* buf, |
| 183 int buf_size) { | 183 int buf_size) { |
| 184 base::ScopedTempDir dir; | 184 base::ScopedTempDir dir; |
| 185 if (!dir.CreateUniqueTempDir()) | 185 if (!dir.CreateUniqueTempDir()) |
| 186 return base::PLATFORM_FILE_ERROR_FAILED; | 186 return base::File::FILE_ERROR_FAILED; |
| 187 base::FilePath local_path = dir.path().AppendASCII("tmp"); | 187 base::FilePath local_path = dir.path().AppendASCII("tmp"); |
| 188 if (buf_size != file_util::WriteFile(local_path, buf, buf_size)) | 188 if (buf_size != file_util::WriteFile(local_path, buf, buf_size)) |
| 189 return base::PLATFORM_FILE_ERROR_FAILED; | 189 return base::File::FILE_ERROR_FAILED; |
| 190 base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED; | 190 base::File::Error result = base::File::FILE_ERROR_FAILED; |
| 191 base::RunLoop run_loop; | 191 base::RunLoop run_loop; |
| 192 context->operation_runner()->CopyInForeignFile( | 192 context->operation_runner()->CopyInForeignFile( |
| 193 local_path, url, AssignAndQuitCallback(&run_loop, &result)); | 193 local_path, url, AssignAndQuitCallback(&run_loop, &result)); |
| 194 run_loop.Run(); | 194 run_loop.Run(); |
| 195 return result; | 195 return result; |
| 196 } | 196 } |
| 197 | 197 |
| 198 base::PlatformFileError AsyncFileTestHelper::TruncateFile( | 198 base::File::Error AsyncFileTestHelper::TruncateFile( |
| 199 FileSystemContext* context, | 199 FileSystemContext* context, |
| 200 const FileSystemURL& url, | 200 const FileSystemURL& url, |
| 201 size_t size) { | 201 size_t size) { |
| 202 base::RunLoop run_loop; | 202 base::RunLoop run_loop; |
| 203 base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED; | 203 base::File::Error result = base::File::FILE_ERROR_FAILED; |
| 204 context->operation_runner()->Truncate( | 204 context->operation_runner()->Truncate( |
| 205 url, size, AssignAndQuitCallback(&run_loop, &result)); | 205 url, size, AssignAndQuitCallback(&run_loop, &result)); |
| 206 run_loop.Run(); | 206 run_loop.Run(); |
| 207 return result; | 207 return result; |
| 208 } | 208 } |
| 209 | 209 |
| 210 base::PlatformFileError AsyncFileTestHelper::GetMetadata( | 210 base::File::Error AsyncFileTestHelper::GetMetadata( |
| 211 FileSystemContext* context, | 211 FileSystemContext* context, |
| 212 const FileSystemURL& url, | 212 const FileSystemURL& url, |
| 213 base::PlatformFileInfo* file_info) { | 213 base::File::Info* file_info) { |
| 214 base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED; | 214 base::File::Error result = base::File::FILE_ERROR_FAILED; |
| 215 base::RunLoop run_loop; | 215 base::RunLoop run_loop; |
| 216 context->operation_runner()->GetMetadata( | 216 context->operation_runner()->GetMetadata( |
| 217 url, base::Bind(&GetMetadataCallback, &run_loop, &result, | 217 url, base::Bind(&GetMetadataCallback, &run_loop, &result, |
| 218 file_info)); | 218 file_info)); |
| 219 run_loop.Run(); | 219 run_loop.Run(); |
| 220 return result; | 220 return result; |
| 221 } | 221 } |
| 222 | 222 |
| 223 base::PlatformFileError AsyncFileTestHelper::GetPlatformPath( | 223 base::File::Error AsyncFileTestHelper::GetPlatformPath( |
| 224 FileSystemContext* context, | 224 FileSystemContext* context, |
| 225 const FileSystemURL& url, | 225 const FileSystemURL& url, |
| 226 base::FilePath* platform_path) { | 226 base::FilePath* platform_path) { |
| 227 base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED; | 227 base::File::Error result = base::File::FILE_ERROR_FAILED; |
| 228 base::RunLoop run_loop; | 228 base::RunLoop run_loop; |
| 229 context->operation_runner()->CreateSnapshotFile( | 229 context->operation_runner()->CreateSnapshotFile( |
| 230 url, base::Bind(&CreateSnapshotFileCallback, &run_loop, &result, | 230 url, base::Bind(&CreateSnapshotFileCallback, &run_loop, &result, |
| 231 platform_path)); | 231 platform_path)); |
| 232 run_loop.Run(); | 232 run_loop.Run(); |
| 233 return result; | 233 return result; |
| 234 } | 234 } |
| 235 | 235 |
| 236 bool AsyncFileTestHelper::FileExists( | 236 bool AsyncFileTestHelper::FileExists( |
| 237 FileSystemContext* context, | 237 FileSystemContext* context, |
| 238 const FileSystemURL& url, | 238 const FileSystemURL& url, |
| 239 int64 expected_size) { | 239 int64 expected_size) { |
| 240 base::PlatformFileInfo file_info; | 240 base::File::Info file_info; |
| 241 base::PlatformFileError result = GetMetadata(context, url, &file_info); | 241 base::File::Error result = GetMetadata(context, url, &file_info); |
| 242 if (result != base::PLATFORM_FILE_OK || file_info.is_directory) | 242 if (result != base::File::FILE_OK || file_info.is_directory) |
| 243 return false; | 243 return false; |
| 244 return expected_size == kDontCheckSize || file_info.size == expected_size; | 244 return expected_size == kDontCheckSize || file_info.size == expected_size; |
| 245 } | 245 } |
| 246 | 246 |
| 247 bool AsyncFileTestHelper::DirectoryExists( | 247 bool AsyncFileTestHelper::DirectoryExists( |
| 248 FileSystemContext* context, | 248 FileSystemContext* context, |
| 249 const FileSystemURL& url) { | 249 const FileSystemURL& url) { |
| 250 base::PlatformFileInfo file_info; | 250 base::File::Info file_info; |
| 251 base::PlatformFileError result = GetMetadata(context, url, &file_info); | 251 base::File::Error result = GetMetadata(context, url, &file_info); |
| 252 return (result == base::PLATFORM_FILE_OK) && file_info.is_directory; | 252 return (result == base::File::FILE_OK) && file_info.is_directory; |
| 253 } | 253 } |
| 254 | 254 |
| 255 quota::QuotaStatusCode AsyncFileTestHelper::GetUsageAndQuota( | 255 quota::QuotaStatusCode AsyncFileTestHelper::GetUsageAndQuota( |
| 256 quota::QuotaManager* quota_manager, | 256 quota::QuotaManager* quota_manager, |
| 257 const GURL& origin, | 257 const GURL& origin, |
| 258 FileSystemType type, | 258 FileSystemType type, |
| 259 int64* usage, | 259 int64* usage, |
| 260 int64* quota) { | 260 int64* quota) { |
| 261 quota::QuotaStatusCode status = quota::kQuotaStatusUnknown; | 261 quota::QuotaStatusCode status = quota::kQuotaStatusUnknown; |
| 262 quota_manager->GetUsageAndQuota( | 262 quota_manager->GetUsageAndQuota( |
| 263 origin, | 263 origin, |
| 264 FileSystemTypeToQuotaStorageType(type), | 264 FileSystemTypeToQuotaStorageType(type), |
| 265 base::Bind(&DidGetUsageAndQuota, &status, usage, quota)); | 265 base::Bind(&DidGetUsageAndQuota, &status, usage, quota)); |
| 266 base::RunLoop().RunUntilIdle(); | 266 base::RunLoop().RunUntilIdle(); |
| 267 return status; | 267 return status; |
| 268 } | 268 } |
| 269 | 269 |
| 270 } // namespace fileapi | 270 } // namespace fileapi |
| OLD | NEW |