OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <map> | 5 #include <map> |
6 #include <queue> | 6 #include <queue> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "webkit/browser/fileapi/file_stream_writer.h" | 22 #include "webkit/browser/fileapi/file_stream_writer.h" |
23 #include "webkit/browser/fileapi/file_system_backend.h" | 23 #include "webkit/browser/fileapi/file_system_backend.h" |
24 #include "webkit/browser/fileapi/file_system_context.h" | 24 #include "webkit/browser/fileapi/file_system_context.h" |
25 #include "webkit/browser/fileapi/file_system_operation.h" | 25 #include "webkit/browser/fileapi/file_system_operation.h" |
26 #include "webkit/browser/fileapi/file_system_url.h" | 26 #include "webkit/browser/fileapi/file_system_url.h" |
27 #include "webkit/browser/fileapi/test_file_set.h" | 27 #include "webkit/browser/fileapi/test_file_set.h" |
28 #include "webkit/browser/quota/mock_quota_manager.h" | 28 #include "webkit/browser/quota/mock_quota_manager.h" |
29 #include "webkit/browser/quota/quota_manager.h" | 29 #include "webkit/browser/quota/quota_manager.h" |
30 #include "webkit/common/fileapi/file_system_util.h" | 30 #include "webkit/common/fileapi/file_system_util.h" |
31 | 31 |
32 namespace fileapi { | 32 using fileapi::AsyncFileTestHelper; |
| 33 using fileapi::CopyOrMoveOperationDelegate; |
| 34 using fileapi::FileStreamWriter; |
| 35 using fileapi::FileSystemOperation; |
| 36 using fileapi::FileSystemType; |
| 37 using fileapi::FileSystemURL; |
| 38 using fileapi::test::TestCaseRecord; |
33 | 39 |
34 typedef FileSystemOperation::FileEntryList FileEntryList; | 40 namespace content { |
| 41 |
| 42 typedef fileapi::FileSystemOperation::FileEntryList FileEntryList; |
35 | 43 |
36 namespace { | 44 namespace { |
37 | 45 |
38 void ExpectOk(const GURL& origin_url, | 46 void ExpectOk(const GURL& origin_url, |
39 const std::string& name, | 47 const std::string& name, |
40 base::PlatformFileError error) { | 48 base::PlatformFileError error) { |
41 ASSERT_EQ(base::PLATFORM_FILE_OK, error); | 49 ASSERT_EQ(base::PLATFORM_FILE_OK, error); |
42 } | 50 } |
43 | 51 |
44 class TestValidatorFactory : public CopyOrMoveFileValidatorFactory { | 52 class TestValidatorFactory : public fileapi::CopyOrMoveFileValidatorFactory { |
45 public: | 53 public: |
46 // A factory that creates validators that accept everything or nothing. | 54 // A factory that creates validators that accept everything or nothing. |
47 TestValidatorFactory() {} | 55 TestValidatorFactory() {} |
48 virtual ~TestValidatorFactory() {} | 56 virtual ~TestValidatorFactory() {} |
49 | 57 |
50 virtual CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator( | 58 virtual fileapi::CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator( |
51 const FileSystemURL& /*src_url*/, | 59 const FileSystemURL& /*src_url*/, |
52 const base::FilePath& /*platform_path*/) OVERRIDE { | 60 const base::FilePath& /*platform_path*/) OVERRIDE { |
53 // Move arg management to TestValidator? | 61 // Move arg management to TestValidator? |
54 return new TestValidator(true, true, std::string("2")); | 62 return new TestValidator(true, true, std::string("2")); |
55 } | 63 } |
56 | 64 |
57 private: | 65 private: |
58 class TestValidator : public CopyOrMoveFileValidator { | 66 class TestValidator : public fileapi::CopyOrMoveFileValidator { |
59 public: | 67 public: |
60 explicit TestValidator(bool pre_copy_valid, | 68 explicit TestValidator(bool pre_copy_valid, |
61 bool post_copy_valid, | 69 bool post_copy_valid, |
62 const std::string& reject_string) | 70 const std::string& reject_string) |
63 : result_(pre_copy_valid ? base::PLATFORM_FILE_OK | 71 : result_(pre_copy_valid ? base::PLATFORM_FILE_OK |
64 : base::PLATFORM_FILE_ERROR_SECURITY), | 72 : base::PLATFORM_FILE_ERROR_SECURITY), |
65 write_result_(post_copy_valid ? base::PLATFORM_FILE_OK | 73 write_result_(post_copy_valid ? base::PLATFORM_FILE_OK |
66 : base::PLATFORM_FILE_ERROR_SECURITY), | 74 : base::PLATFORM_FILE_ERROR_SECURITY), |
67 reject_string_(reject_string) { | 75 reject_string_(reject_string) { |
68 } | 76 } |
(...skipping 23 matching lines...) Expand all Loading... |
92 base::PlatformFileError result_; | 100 base::PlatformFileError result_; |
93 base::PlatformFileError write_result_; | 101 base::PlatformFileError write_result_; |
94 std::string reject_string_; | 102 std::string reject_string_; |
95 | 103 |
96 DISALLOW_COPY_AND_ASSIGN(TestValidator); | 104 DISALLOW_COPY_AND_ASSIGN(TestValidator); |
97 }; | 105 }; |
98 }; | 106 }; |
99 | 107 |
100 // Records CopyProgressCallback invocations. | 108 // Records CopyProgressCallback invocations. |
101 struct ProgressRecord { | 109 struct ProgressRecord { |
102 FileSystemOperation::CopyProgressType type; | 110 fileapi::FileSystemOperation::CopyProgressType type; |
103 FileSystemURL source_url; | 111 FileSystemURL source_url; |
104 FileSystemURL dest_url; | 112 FileSystemURL dest_url; |
105 int64 size; | 113 int64 size; |
106 }; | 114 }; |
107 | 115 |
108 void RecordProgressCallback(std::vector<ProgressRecord>* records, | 116 void RecordProgressCallback(std::vector<ProgressRecord>* records, |
109 FileSystemOperation::CopyProgressType type, | 117 fileapi::FileSystemOperation::CopyProgressType type, |
110 const FileSystemURL& source_url, | 118 const FileSystemURL& source_url, |
111 const FileSystemURL& dest_url, | 119 const FileSystemURL& dest_url, |
112 int64 size) { | 120 int64 size) { |
113 ProgressRecord record; | 121 ProgressRecord record; |
114 record.type = type; | 122 record.type = type; |
115 record.source_url = source_url; | 123 record.source_url = source_url; |
116 record.dest_url = dest_url; | 124 record.dest_url = dest_url; |
117 record.size = size; | 125 record.size = size; |
118 records->push_back(record); | 126 records->push_back(record); |
119 } | 127 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 base_dir, | 198 base_dir, |
191 base::MessageLoopProxy::current().get(), | 199 base::MessageLoopProxy::current().get(), |
192 base::MessageLoopProxy::current().get(), | 200 base::MessageLoopProxy::current().get(), |
193 NULL /* special storage policy */); | 201 NULL /* special storage policy */); |
194 quota_manager_proxy_ = new quota::MockQuotaManagerProxy( | 202 quota_manager_proxy_ = new quota::MockQuotaManagerProxy( |
195 quota_manager_.get(), base::MessageLoopProxy::current().get()); | 203 quota_manager_.get(), base::MessageLoopProxy::current().get()); |
196 file_system_context_ = | 204 file_system_context_ = |
197 CreateFileSystemContextForTesting(quota_manager_proxy_.get(), base_dir); | 205 CreateFileSystemContextForTesting(quota_manager_proxy_.get(), base_dir); |
198 | 206 |
199 // Prepare the origin's root directory. | 207 // Prepare the origin's root directory. |
200 FileSystemBackend* backend = | 208 fileapi::FileSystemBackend* backend = |
201 file_system_context_->GetFileSystemBackend(src_type_); | 209 file_system_context_->GetFileSystemBackend(src_type_); |
202 backend->OpenFileSystem(origin_, src_type_, | 210 backend->OpenFileSystem(origin_, src_type_, |
203 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 211 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
204 base::Bind(&ExpectOk)); | 212 base::Bind(&ExpectOk)); |
205 backend = file_system_context_->GetFileSystemBackend(dest_type_); | 213 backend = file_system_context_->GetFileSystemBackend(dest_type_); |
206 if (dest_type_ == kFileSystemTypeTest) { | 214 if (dest_type_ == fileapi::kFileSystemTypeTest) { |
207 TestFileSystemBackend* test_backend = | 215 TestFileSystemBackend* test_backend = |
208 static_cast<TestFileSystemBackend*>(backend); | 216 static_cast<TestFileSystemBackend*>(backend); |
209 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( | 217 scoped_ptr<fileapi::CopyOrMoveFileValidatorFactory> factory( |
210 new TestValidatorFactory); | 218 new TestValidatorFactory); |
211 test_backend->set_require_copy_or_move_validator( | 219 test_backend->set_require_copy_or_move_validator( |
212 require_copy_or_move_validator); | 220 require_copy_or_move_validator); |
213 if (init_copy_or_move_validator) | 221 if (init_copy_or_move_validator) |
214 test_backend->InitializeCopyOrMoveFileValidatorFactory(factory.Pass()); | 222 test_backend->InitializeCopyOrMoveFileValidatorFactory(factory.Pass()); |
215 } | 223 } |
216 backend->OpenFileSystem(origin_, dest_type_, | 224 backend->OpenFileSystem(origin_, dest_type_, |
217 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 225 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
218 base::Bind(&ExpectOk)); | 226 base::Bind(&ExpectOk)); |
219 base::RunLoop().RunUntilIdle(); | 227 base::RunLoop().RunUntilIdle(); |
220 | 228 |
221 // Grant relatively big quota initially. | 229 // Grant relatively big quota initially. |
222 quota_manager_->SetQuota(origin_, | 230 quota_manager_->SetQuota( |
223 FileSystemTypeToQuotaStorageType(src_type_), | 231 origin_, |
224 1024 * 1024); | 232 fileapi::FileSystemTypeToQuotaStorageType(src_type_), |
225 quota_manager_->SetQuota(origin_, | 233 1024 * 1024); |
226 FileSystemTypeToQuotaStorageType(dest_type_), | 234 quota_manager_->SetQuota( |
227 1024 * 1024); | 235 origin_, |
| 236 fileapi::FileSystemTypeToQuotaStorageType(dest_type_), |
| 237 1024 * 1024); |
228 } | 238 } |
229 | 239 |
230 int64 GetSourceUsage() { | 240 int64 GetSourceUsage() { |
231 int64 usage = 0; | 241 int64 usage = 0; |
232 GetUsageAndQuota(src_type_, &usage, NULL); | 242 GetUsageAndQuota(src_type_, &usage, NULL); |
233 return usage; | 243 return usage; |
234 } | 244 } |
235 | 245 |
236 int64 GetDestUsage() { | 246 int64 GetDestUsage() { |
237 int64 usage = 0; | 247 int64 usage = 0; |
(...skipping 24 matching lines...) Expand all Loading... |
262 file_system_context_.get(), src, dest, progress_callback); | 272 file_system_context_.get(), src, dest, progress_callback); |
263 } | 273 } |
264 | 274 |
265 base::PlatformFileError Move(const FileSystemURL& src, | 275 base::PlatformFileError Move(const FileSystemURL& src, |
266 const FileSystemURL& dest) { | 276 const FileSystemURL& dest) { |
267 return AsyncFileTestHelper::Move(file_system_context_.get(), src, dest); | 277 return AsyncFileTestHelper::Move(file_system_context_.get(), src, dest); |
268 } | 278 } |
269 | 279 |
270 base::PlatformFileError SetUpTestCaseFiles( | 280 base::PlatformFileError SetUpTestCaseFiles( |
271 const FileSystemURL& root, | 281 const FileSystemURL& root, |
272 const test::TestCaseRecord* const test_cases, | 282 const TestCaseRecord* const test_cases, |
273 size_t test_case_size) { | 283 size_t test_case_size) { |
274 base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED; | 284 base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED; |
275 for (size_t i = 0; i < test_case_size; ++i) { | 285 for (size_t i = 0; i < test_case_size; ++i) { |
276 const test::TestCaseRecord& test_case = test_cases[i]; | 286 const TestCaseRecord& test_case = test_cases[i]; |
277 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( | 287 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( |
278 root.origin(), | 288 root.origin(), |
279 root.mount_type(), | 289 root.mount_type(), |
280 root.virtual_path().Append(test_case.path)); | 290 root.virtual_path().Append(test_case.path)); |
281 if (test_case.is_directory) | 291 if (test_case.is_directory) |
282 result = CreateDirectory(url); | 292 result = CreateDirectory(url); |
283 else | 293 else |
284 result = CreateFile(url, test_case.data_file_size); | 294 result = CreateFile(url, test_case.data_file_size); |
285 EXPECT_EQ(base::PLATFORM_FILE_OK, result) << url.DebugString(); | 295 EXPECT_EQ(base::PLATFORM_FILE_OK, result) << url.DebugString(); |
286 if (result != base::PLATFORM_FILE_OK) | 296 if (result != base::PLATFORM_FILE_OK) |
287 return result; | 297 return result; |
288 } | 298 } |
289 return result; | 299 return result; |
290 } | 300 } |
291 | 301 |
292 void VerifyTestCaseFiles( | 302 void VerifyTestCaseFiles( |
293 const FileSystemURL& root, | 303 const FileSystemURL& root, |
294 const test::TestCaseRecord* const test_cases, | 304 const TestCaseRecord* const test_cases, |
295 size_t test_case_size) { | 305 size_t test_case_size) { |
296 std::map<base::FilePath, const test::TestCaseRecord*> test_case_map; | 306 std::map<base::FilePath, const TestCaseRecord*> test_case_map; |
297 for (size_t i = 0; i < test_case_size; ++i) { | 307 for (size_t i = 0; i < test_case_size; ++i) { |
298 test_case_map[ | 308 test_case_map[ |
299 base::FilePath(test_cases[i].path).NormalizePathSeparators()] = | 309 base::FilePath(test_cases[i].path).NormalizePathSeparators()] = |
300 &test_cases[i]; | 310 &test_cases[i]; |
301 } | 311 } |
302 | 312 |
303 std::queue<FileSystemURL> directories; | 313 std::queue<FileSystemURL> directories; |
304 FileEntryList entries; | 314 FileEntryList entries; |
305 directories.push(root); | 315 directories.push(root); |
306 while (!directories.empty()) { | 316 while (!directories.empty()) { |
(...skipping 13 matching lines...) Expand all Loading... |
320 EXPECT_TRUE(test_case_map[relative]->is_directory); | 330 EXPECT_TRUE(test_case_map[relative]->is_directory); |
321 directories.push(url); | 331 directories.push(url); |
322 } else { | 332 } else { |
323 EXPECT_FALSE(test_case_map[relative]->is_directory); | 333 EXPECT_FALSE(test_case_map[relative]->is_directory); |
324 EXPECT_TRUE(FileExists(url, test_case_map[relative]->data_file_size)); | 334 EXPECT_TRUE(FileExists(url, test_case_map[relative]->data_file_size)); |
325 } | 335 } |
326 test_case_map.erase(relative); | 336 test_case_map.erase(relative); |
327 } | 337 } |
328 } | 338 } |
329 EXPECT_TRUE(test_case_map.empty()); | 339 EXPECT_TRUE(test_case_map.empty()); |
330 std::map<base::FilePath, const test::TestCaseRecord*>::const_iterator it; | 340 std::map<base::FilePath, const TestCaseRecord*>::const_iterator it; |
331 for (it = test_case_map.begin(); it != test_case_map.end(); ++it) { | 341 for (it = test_case_map.begin(); it != test_case_map.end(); ++it) { |
332 LOG(ERROR) << "Extra entry: " << it->first.LossyDisplayName(); | 342 LOG(ERROR) << "Extra entry: " << it->first.LossyDisplayName(); |
333 } | 343 } |
334 } | 344 } |
335 | 345 |
336 base::PlatformFileError ReadDirectory(const FileSystemURL& url, | 346 base::PlatformFileError ReadDirectory(const FileSystemURL& url, |
337 FileEntryList* entries) { | 347 FileEntryList* entries) { |
338 return AsyncFileTestHelper::ReadDirectory( | 348 return AsyncFileTestHelper::ReadDirectory( |
339 file_system_context_.get(), url, entries); | 349 file_system_context_.get(), url, entries); |
340 } | 350 } |
(...skipping 30 matching lines...) Expand all Loading... |
371 } | 381 } |
372 | 382 |
373 private: | 383 private: |
374 base::ScopedTempDir base_; | 384 base::ScopedTempDir base_; |
375 | 385 |
376 const GURL origin_; | 386 const GURL origin_; |
377 const FileSystemType src_type_; | 387 const FileSystemType src_type_; |
378 const FileSystemType dest_type_; | 388 const FileSystemType dest_type_; |
379 | 389 |
380 base::MessageLoopForIO message_loop_; | 390 base::MessageLoopForIO message_loop_; |
381 scoped_refptr<FileSystemContext> file_system_context_; | 391 scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
382 scoped_refptr<quota::MockQuotaManagerProxy> quota_manager_proxy_; | 392 scoped_refptr<quota::MockQuotaManagerProxy> quota_manager_proxy_; |
383 scoped_refptr<quota::MockQuotaManager> quota_manager_; | 393 scoped_refptr<quota::MockQuotaManager> quota_manager_; |
384 | 394 |
385 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveOperationTestHelper); | 395 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveOperationTestHelper); |
386 }; | 396 }; |
387 | 397 |
388 TEST(LocalFileSystemCopyOrMoveOperationTest, CopySingleFile) { | 398 TEST(LocalFileSystemCopyOrMoveOperationTest, CopySingleFile) { |
389 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), | 399 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), |
390 kFileSystemTypeTemporary, | 400 fileapi::kFileSystemTypeTemporary, |
391 kFileSystemTypePersistent); | 401 fileapi::kFileSystemTypePersistent); |
392 helper.SetUp(); | 402 helper.SetUp(); |
393 | 403 |
394 FileSystemURL src = helper.SourceURL("a"); | 404 FileSystemURL src = helper.SourceURL("a"); |
395 FileSystemURL dest = helper.DestURL("b"); | 405 FileSystemURL dest = helper.DestURL("b"); |
396 int64 src_initial_usage = helper.GetSourceUsage(); | 406 int64 src_initial_usage = helper.GetSourceUsage(); |
397 int64 dest_initial_usage = helper.GetDestUsage(); | 407 int64 dest_initial_usage = helper.GetDestUsage(); |
398 | 408 |
399 // Set up a source file. | 409 // Set up a source file. |
400 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateFile(src, 10)); | 410 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateFile(src, 10)); |
401 int64 src_increase = helper.GetSourceUsage() - src_initial_usage; | 411 int64 src_increase = helper.GetSourceUsage() - src_initial_usage; |
402 | 412 |
403 // Copy it. | 413 // Copy it. |
404 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.Copy(src, dest)); | 414 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.Copy(src, dest)); |
405 | 415 |
406 // Verify. | 416 // Verify. |
407 ASSERT_TRUE(helper.FileExists(src, 10)); | 417 ASSERT_TRUE(helper.FileExists(src, 10)); |
408 ASSERT_TRUE(helper.FileExists(dest, 10)); | 418 ASSERT_TRUE(helper.FileExists(dest, 10)); |
409 | 419 |
410 int64 src_new_usage = helper.GetSourceUsage(); | 420 int64 src_new_usage = helper.GetSourceUsage(); |
411 ASSERT_EQ(src_initial_usage + src_increase, src_new_usage); | 421 ASSERT_EQ(src_initial_usage + src_increase, src_new_usage); |
412 | 422 |
413 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage; | 423 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage; |
414 ASSERT_EQ(src_increase, dest_increase); | 424 ASSERT_EQ(src_increase, dest_increase); |
415 } | 425 } |
416 | 426 |
417 TEST(LocalFileSystemCopyOrMoveOperationTest, MoveSingleFile) { | 427 TEST(LocalFileSystemCopyOrMoveOperationTest, MoveSingleFile) { |
418 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), | 428 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), |
419 kFileSystemTypeTemporary, | 429 fileapi::kFileSystemTypeTemporary, |
420 kFileSystemTypePersistent); | 430 fileapi::kFileSystemTypePersistent); |
421 helper.SetUp(); | 431 helper.SetUp(); |
422 | 432 |
423 FileSystemURL src = helper.SourceURL("a"); | 433 FileSystemURL src = helper.SourceURL("a"); |
424 FileSystemURL dest = helper.DestURL("b"); | 434 FileSystemURL dest = helper.DestURL("b"); |
425 int64 src_initial_usage = helper.GetSourceUsage(); | 435 int64 src_initial_usage = helper.GetSourceUsage(); |
426 int64 dest_initial_usage = helper.GetDestUsage(); | 436 int64 dest_initial_usage = helper.GetDestUsage(); |
427 | 437 |
428 // Set up a source file. | 438 // Set up a source file. |
429 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateFile(src, 10)); | 439 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateFile(src, 10)); |
430 int64 src_increase = helper.GetSourceUsage() - src_initial_usage; | 440 int64 src_increase = helper.GetSourceUsage() - src_initial_usage; |
431 | 441 |
432 // Move it. | 442 // Move it. |
433 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.Move(src, dest)); | 443 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.Move(src, dest)); |
434 | 444 |
435 // Verify. | 445 // Verify. |
436 ASSERT_FALSE(helper.FileExists(src, AsyncFileTestHelper::kDontCheckSize)); | 446 ASSERT_FALSE(helper.FileExists(src, AsyncFileTestHelper::kDontCheckSize)); |
437 ASSERT_TRUE(helper.FileExists(dest, 10)); | 447 ASSERT_TRUE(helper.FileExists(dest, 10)); |
438 | 448 |
439 int64 src_new_usage = helper.GetSourceUsage(); | 449 int64 src_new_usage = helper.GetSourceUsage(); |
440 ASSERT_EQ(src_initial_usage, src_new_usage); | 450 ASSERT_EQ(src_initial_usage, src_new_usage); |
441 | 451 |
442 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage; | 452 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage; |
443 ASSERT_EQ(src_increase, dest_increase); | 453 ASSERT_EQ(src_increase, dest_increase); |
444 } | 454 } |
445 | 455 |
446 TEST(LocalFileSystemCopyOrMoveOperationTest, CopySingleDirectory) { | 456 TEST(LocalFileSystemCopyOrMoveOperationTest, CopySingleDirectory) { |
447 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), | 457 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), |
448 kFileSystemTypeTemporary, | 458 fileapi::kFileSystemTypeTemporary, |
449 kFileSystemTypePersistent); | 459 fileapi::kFileSystemTypePersistent); |
450 helper.SetUp(); | 460 helper.SetUp(); |
451 | 461 |
452 FileSystemURL src = helper.SourceURL("a"); | 462 FileSystemURL src = helper.SourceURL("a"); |
453 FileSystemURL dest = helper.DestURL("b"); | 463 FileSystemURL dest = helper.DestURL("b"); |
454 int64 src_initial_usage = helper.GetSourceUsage(); | 464 int64 src_initial_usage = helper.GetSourceUsage(); |
455 int64 dest_initial_usage = helper.GetDestUsage(); | 465 int64 dest_initial_usage = helper.GetDestUsage(); |
456 | 466 |
457 // Set up a source directory. | 467 // Set up a source directory. |
458 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateDirectory(src)); | 468 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateDirectory(src)); |
459 int64 src_increase = helper.GetSourceUsage() - src_initial_usage; | 469 int64 src_increase = helper.GetSourceUsage() - src_initial_usage; |
460 | 470 |
461 // Copy it. | 471 // Copy it. |
462 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.Copy(src, dest)); | 472 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.Copy(src, dest)); |
463 | 473 |
464 // Verify. | 474 // Verify. |
465 ASSERT_TRUE(helper.DirectoryExists(src)); | 475 ASSERT_TRUE(helper.DirectoryExists(src)); |
466 ASSERT_TRUE(helper.DirectoryExists(dest)); | 476 ASSERT_TRUE(helper.DirectoryExists(dest)); |
467 | 477 |
468 int64 src_new_usage = helper.GetSourceUsage(); | 478 int64 src_new_usage = helper.GetSourceUsage(); |
469 ASSERT_EQ(src_initial_usage + src_increase, src_new_usage); | 479 ASSERT_EQ(src_initial_usage + src_increase, src_new_usage); |
470 | 480 |
471 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage; | 481 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage; |
472 ASSERT_EQ(src_increase, dest_increase); | 482 ASSERT_EQ(src_increase, dest_increase); |
473 } | 483 } |
474 | 484 |
475 TEST(LocalFileSystemCopyOrMoveOperationTest, MoveSingleDirectory) { | 485 TEST(LocalFileSystemCopyOrMoveOperationTest, MoveSingleDirectory) { |
476 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), | 486 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), |
477 kFileSystemTypeTemporary, | 487 fileapi::kFileSystemTypeTemporary, |
478 kFileSystemTypePersistent); | 488 fileapi::kFileSystemTypePersistent); |
479 helper.SetUp(); | 489 helper.SetUp(); |
480 | 490 |
481 FileSystemURL src = helper.SourceURL("a"); | 491 FileSystemURL src = helper.SourceURL("a"); |
482 FileSystemURL dest = helper.DestURL("b"); | 492 FileSystemURL dest = helper.DestURL("b"); |
483 int64 src_initial_usage = helper.GetSourceUsage(); | 493 int64 src_initial_usage = helper.GetSourceUsage(); |
484 int64 dest_initial_usage = helper.GetDestUsage(); | 494 int64 dest_initial_usage = helper.GetDestUsage(); |
485 | 495 |
486 // Set up a source directory. | 496 // Set up a source directory. |
487 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateDirectory(src)); | 497 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateDirectory(src)); |
488 int64 src_increase = helper.GetSourceUsage() - src_initial_usage; | 498 int64 src_increase = helper.GetSourceUsage() - src_initial_usage; |
489 | 499 |
490 // Move it. | 500 // Move it. |
491 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.Move(src, dest)); | 501 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.Move(src, dest)); |
492 | 502 |
493 // Verify. | 503 // Verify. |
494 ASSERT_FALSE(helper.DirectoryExists(src)); | 504 ASSERT_FALSE(helper.DirectoryExists(src)); |
495 ASSERT_TRUE(helper.DirectoryExists(dest)); | 505 ASSERT_TRUE(helper.DirectoryExists(dest)); |
496 | 506 |
497 int64 src_new_usage = helper.GetSourceUsage(); | 507 int64 src_new_usage = helper.GetSourceUsage(); |
498 ASSERT_EQ(src_initial_usage, src_new_usage); | 508 ASSERT_EQ(src_initial_usage, src_new_usage); |
499 | 509 |
500 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage; | 510 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage; |
501 ASSERT_EQ(src_increase, dest_increase); | 511 ASSERT_EQ(src_increase, dest_increase); |
502 } | 512 } |
503 | 513 |
504 TEST(LocalFileSystemCopyOrMoveOperationTest, CopyDirectory) { | 514 TEST(LocalFileSystemCopyOrMoveOperationTest, CopyDirectory) { |
505 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), | 515 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), |
506 kFileSystemTypeTemporary, | 516 fileapi::kFileSystemTypeTemporary, |
507 kFileSystemTypePersistent); | 517 fileapi::kFileSystemTypePersistent); |
508 helper.SetUp(); | 518 helper.SetUp(); |
509 | 519 |
510 FileSystemURL src = helper.SourceURL("a"); | 520 FileSystemURL src = helper.SourceURL("a"); |
511 FileSystemURL dest = helper.DestURL("b"); | 521 FileSystemURL dest = helper.DestURL("b"); |
512 int64 src_initial_usage = helper.GetSourceUsage(); | 522 int64 src_initial_usage = helper.GetSourceUsage(); |
513 int64 dest_initial_usage = helper.GetDestUsage(); | 523 int64 dest_initial_usage = helper.GetDestUsage(); |
514 | 524 |
515 // Set up a source directory. | 525 // Set up a source directory. |
516 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateDirectory(src)); | 526 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateDirectory(src)); |
517 ASSERT_EQ(base::PLATFORM_FILE_OK, | 527 ASSERT_EQ(base::PLATFORM_FILE_OK, |
518 helper.SetUpTestCaseFiles(src, | 528 helper.SetUpTestCaseFiles(src, |
519 test::kRegularTestCases, | 529 fileapi::test::kRegularTestCases, |
520 test::kRegularTestCaseSize)); | 530 fileapi::test::kRegularTestCaseSize)); |
521 int64 src_increase = helper.GetSourceUsage() - src_initial_usage; | 531 int64 src_increase = helper.GetSourceUsage() - src_initial_usage; |
522 | 532 |
523 // Copy it. | 533 // Copy it. |
524 ASSERT_EQ(base::PLATFORM_FILE_OK, | 534 ASSERT_EQ(base::PLATFORM_FILE_OK, |
525 helper.CopyWithProgress( | 535 helper.CopyWithProgress( |
526 src, dest, | 536 src, dest, |
527 AsyncFileTestHelper::CopyProgressCallback())); | 537 AsyncFileTestHelper::CopyProgressCallback())); |
528 | 538 |
529 // Verify. | 539 // Verify. |
530 ASSERT_TRUE(helper.DirectoryExists(src)); | 540 ASSERT_TRUE(helper.DirectoryExists(src)); |
531 ASSERT_TRUE(helper.DirectoryExists(dest)); | 541 ASSERT_TRUE(helper.DirectoryExists(dest)); |
532 | 542 |
533 helper.VerifyTestCaseFiles(dest, | 543 helper.VerifyTestCaseFiles(dest, |
534 test::kRegularTestCases, | 544 fileapi::test::kRegularTestCases, |
535 test::kRegularTestCaseSize); | 545 fileapi::test::kRegularTestCaseSize); |
536 | 546 |
537 int64 src_new_usage = helper.GetSourceUsage(); | 547 int64 src_new_usage = helper.GetSourceUsage(); |
538 ASSERT_EQ(src_initial_usage + src_increase, src_new_usage); | 548 ASSERT_EQ(src_initial_usage + src_increase, src_new_usage); |
539 | 549 |
540 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage; | 550 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage; |
541 ASSERT_EQ(src_increase, dest_increase); | 551 ASSERT_EQ(src_increase, dest_increase); |
542 } | 552 } |
543 | 553 |
544 TEST(LocalFileSystemCopyOrMoveOperationTest, MoveDirectory) { | 554 TEST(LocalFileSystemCopyOrMoveOperationTest, MoveDirectory) { |
545 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), | 555 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), |
546 kFileSystemTypeTemporary, | 556 fileapi::kFileSystemTypeTemporary, |
547 kFileSystemTypePersistent); | 557 fileapi::kFileSystemTypePersistent); |
548 helper.SetUp(); | 558 helper.SetUp(); |
549 | 559 |
550 FileSystemURL src = helper.SourceURL("a"); | 560 FileSystemURL src = helper.SourceURL("a"); |
551 FileSystemURL dest = helper.DestURL("b"); | 561 FileSystemURL dest = helper.DestURL("b"); |
552 int64 src_initial_usage = helper.GetSourceUsage(); | 562 int64 src_initial_usage = helper.GetSourceUsage(); |
553 int64 dest_initial_usage = helper.GetDestUsage(); | 563 int64 dest_initial_usage = helper.GetDestUsage(); |
554 | 564 |
555 // Set up a source directory. | 565 // Set up a source directory. |
556 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateDirectory(src)); | 566 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateDirectory(src)); |
557 ASSERT_EQ(base::PLATFORM_FILE_OK, | 567 ASSERT_EQ(base::PLATFORM_FILE_OK, |
558 helper.SetUpTestCaseFiles(src, | 568 helper.SetUpTestCaseFiles(src, |
559 test::kRegularTestCases, | 569 fileapi::test::kRegularTestCases, |
560 test::kRegularTestCaseSize)); | 570 fileapi::test::kRegularTestCaseSize)); |
561 int64 src_increase = helper.GetSourceUsage() - src_initial_usage; | 571 int64 src_increase = helper.GetSourceUsage() - src_initial_usage; |
562 | 572 |
563 // Move it. | 573 // Move it. |
564 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.Move(src, dest)); | 574 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.Move(src, dest)); |
565 | 575 |
566 // Verify. | 576 // Verify. |
567 ASSERT_FALSE(helper.DirectoryExists(src)); | 577 ASSERT_FALSE(helper.DirectoryExists(src)); |
568 ASSERT_TRUE(helper.DirectoryExists(dest)); | 578 ASSERT_TRUE(helper.DirectoryExists(dest)); |
569 | 579 |
570 helper.VerifyTestCaseFiles(dest, | 580 helper.VerifyTestCaseFiles(dest, |
571 test::kRegularTestCases, | 581 fileapi::test::kRegularTestCases, |
572 test::kRegularTestCaseSize); | 582 fileapi::test::kRegularTestCaseSize); |
573 | 583 |
574 int64 src_new_usage = helper.GetSourceUsage(); | 584 int64 src_new_usage = helper.GetSourceUsage(); |
575 ASSERT_EQ(src_initial_usage, src_new_usage); | 585 ASSERT_EQ(src_initial_usage, src_new_usage); |
576 | 586 |
577 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage; | 587 int64 dest_increase = helper.GetDestUsage() - dest_initial_usage; |
578 ASSERT_EQ(src_increase, dest_increase); | 588 ASSERT_EQ(src_increase, dest_increase); |
579 } | 589 } |
580 | 590 |
581 TEST(LocalFileSystemCopyOrMoveOperationTest, | 591 TEST(LocalFileSystemCopyOrMoveOperationTest, |
582 MoveDirectoryFailPostWriteValidation) { | 592 MoveDirectoryFailPostWriteValidation) { |
583 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), | 593 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), |
584 kFileSystemTypeTemporary, | 594 fileapi::kFileSystemTypeTemporary, |
585 kFileSystemTypeTest); | 595 fileapi::kFileSystemTypeTest); |
586 helper.SetUp(); | 596 helper.SetUp(); |
587 | 597 |
588 FileSystemURL src = helper.SourceURL("a"); | 598 FileSystemURL src = helper.SourceURL("a"); |
589 FileSystemURL dest = helper.DestURL("b"); | 599 FileSystemURL dest = helper.DestURL("b"); |
590 | 600 |
591 // Set up a source directory. | 601 // Set up a source directory. |
592 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateDirectory(src)); | 602 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateDirectory(src)); |
593 ASSERT_EQ(base::PLATFORM_FILE_OK, | 603 ASSERT_EQ(base::PLATFORM_FILE_OK, |
594 helper.SetUpTestCaseFiles(src, | 604 helper.SetUpTestCaseFiles(src, |
595 test::kRegularTestCases, | 605 fileapi::test::kRegularTestCases, |
596 test::kRegularTestCaseSize)); | 606 fileapi::test::kRegularTestCaseSize)); |
597 | 607 |
598 // Move it. | 608 // Move it. |
599 helper.Move(src, dest); | 609 helper.Move(src, dest); |
600 | 610 |
601 // Verify. | 611 // Verify. |
602 ASSERT_TRUE(helper.DirectoryExists(src)); | 612 ASSERT_TRUE(helper.DirectoryExists(src)); |
603 ASSERT_TRUE(helper.DirectoryExists(dest)); | 613 ASSERT_TRUE(helper.DirectoryExists(dest)); |
604 | 614 |
605 test::TestCaseRecord kMoveDirResultCases[] = { | 615 TestCaseRecord kMoveDirResultCases[] = { |
606 {false, FILE_PATH_LITERAL("file 0"), 38}, | 616 {false, FILE_PATH_LITERAL("file 0"), 38}, |
607 {false, FILE_PATH_LITERAL("file 3"), 0}, | 617 {false, FILE_PATH_LITERAL("file 3"), 0}, |
608 }; | 618 }; |
609 | 619 |
610 helper.VerifyTestCaseFiles(dest, | 620 helper.VerifyTestCaseFiles(dest, |
611 kMoveDirResultCases, | 621 kMoveDirResultCases, |
612 arraysize(kMoveDirResultCases)); | 622 arraysize(kMoveDirResultCases)); |
613 } | 623 } |
614 | 624 |
615 TEST(LocalFileSystemCopyOrMoveOperationTest, CopySingleFileNoValidator) { | 625 TEST(LocalFileSystemCopyOrMoveOperationTest, CopySingleFileNoValidator) { |
616 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), | 626 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), |
617 kFileSystemTypeTemporary, | 627 fileapi::kFileSystemTypeTemporary, |
618 kFileSystemTypeTest); | 628 fileapi::kFileSystemTypeTest); |
619 helper.SetUpNoValidator(); | 629 helper.SetUpNoValidator(); |
620 | 630 |
621 FileSystemURL src = helper.SourceURL("a"); | 631 FileSystemURL src = helper.SourceURL("a"); |
622 FileSystemURL dest = helper.DestURL("b"); | 632 FileSystemURL dest = helper.DestURL("b"); |
623 | 633 |
624 // Set up a source file. | 634 // Set up a source file. |
625 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateFile(src, 10)); | 635 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateFile(src, 10)); |
626 | 636 |
627 // The copy attempt should fail with a security error -- getting | 637 // The copy attempt should fail with a security error -- getting |
628 // the factory returns a security error, and the copy operation must | 638 // the factory returns a security error, and the copy operation must |
629 // respect that. | 639 // respect that. |
630 ASSERT_EQ(base::PLATFORM_FILE_ERROR_SECURITY, helper.Copy(src, dest)); | 640 ASSERT_EQ(base::PLATFORM_FILE_ERROR_SECURITY, helper.Copy(src, dest)); |
631 } | 641 } |
632 | 642 |
633 TEST(LocalFileSystemCopyOrMoveOperationTest, ProgressCallback) { | 643 TEST(LocalFileSystemCopyOrMoveOperationTest, ProgressCallback) { |
634 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), | 644 CopyOrMoveOperationTestHelper helper(GURL("http://foo"), |
635 kFileSystemTypeTemporary, | 645 fileapi::kFileSystemTypeTemporary, |
636 kFileSystemTypePersistent); | 646 fileapi::kFileSystemTypePersistent); |
637 helper.SetUp(); | 647 helper.SetUp(); |
638 | 648 |
639 FileSystemURL src = helper.SourceURL("a"); | 649 FileSystemURL src = helper.SourceURL("a"); |
640 FileSystemURL dest = helper.DestURL("b"); | 650 FileSystemURL dest = helper.DestURL("b"); |
641 | 651 |
642 // Set up a source directory. | 652 // Set up a source directory. |
643 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateDirectory(src)); | 653 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateDirectory(src)); |
644 ASSERT_EQ(base::PLATFORM_FILE_OK, | 654 ASSERT_EQ(base::PLATFORM_FILE_OK, |
645 helper.SetUpTestCaseFiles(src, | 655 helper.SetUpTestCaseFiles(src, |
646 test::kRegularTestCases, | 656 fileapi::test::kRegularTestCases, |
647 test::kRegularTestCaseSize)); | 657 fileapi::test::kRegularTestCaseSize)); |
648 | 658 |
649 std::vector<ProgressRecord> records; | 659 std::vector<ProgressRecord> records; |
650 ASSERT_EQ(base::PLATFORM_FILE_OK, | 660 ASSERT_EQ(base::PLATFORM_FILE_OK, |
651 helper.CopyWithProgress(src, dest, | 661 helper.CopyWithProgress(src, dest, |
652 base::Bind(&RecordProgressCallback, | 662 base::Bind(&RecordProgressCallback, |
653 base::Unretained(&records)))); | 663 base::Unretained(&records)))); |
654 | 664 |
655 // Verify progress callback. | 665 // Verify progress callback. |
656 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { | 666 for (size_t i = 0; i < fileapi::test::kRegularTestCaseSize; ++i) { |
657 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; | 667 const TestCaseRecord& test_case = fileapi::test::kRegularTestCases[i]; |
658 | 668 |
659 FileSystemURL src_url = helper.SourceURL( | 669 FileSystemURL src_url = helper.SourceURL( |
660 std::string("a/") + base::FilePath(test_case.path).AsUTF8Unsafe()); | 670 std::string("a/") + base::FilePath(test_case.path).AsUTF8Unsafe()); |
661 FileSystemURL dest_url = helper.DestURL( | 671 FileSystemURL dest_url = helper.DestURL( |
662 std::string("b/") + base::FilePath(test_case.path).AsUTF8Unsafe()); | 672 std::string("b/") + base::FilePath(test_case.path).AsUTF8Unsafe()); |
663 | 673 |
664 // Find the first and last progress record. | 674 // Find the first and last progress record. |
665 size_t begin_index = records.size(); | 675 size_t begin_index = records.size(); |
666 size_t end_index = records.size(); | 676 size_t end_index = records.size(); |
667 for (size_t j = 0; j < records.size(); ++j) { | 677 for (size_t j = 0; j < records.size(); ++j) { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 base::Unretained(&helper))); | 866 base::Unretained(&helper))); |
857 | 867 |
858 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; | 868 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; |
859 base::RunLoop run_loop; | 869 base::RunLoop run_loop; |
860 helper.Run(base::Bind(&AssignAndQuit, &run_loop, &error)); | 870 helper.Run(base::Bind(&AssignAndQuit, &run_loop, &error)); |
861 run_loop.Run(); | 871 run_loop.Run(); |
862 | 872 |
863 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ABORT, error); | 873 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ABORT, error); |
864 } | 874 } |
865 | 875 |
866 } // namespace fileapi | 876 } // namespace content |
OLD | NEW |