OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/file_system_operation.h" | 5 #include "webkit/fileapi/file_system_operation.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 ScopedTempDir dir; | 421 ScopedTempDir dir; |
422 ASSERT_TRUE(dir.CreateUniqueTempDir()); | 422 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
423 FilePath file; | 423 FilePath file; |
424 | 424 |
425 file_util::CreateTemporaryFileInDir(dir.path(), &file); | 425 file_util::CreateTemporaryFileInDir(dir.path(), &file); |
426 operation()->CreateFile(file, true); | 426 operation()->CreateFile(file, true); |
427 MessageLoop::current()->RunAllPending(); | 427 MessageLoop::current()->RunAllPending(); |
428 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); | 428 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); |
429 } | 429 } |
430 | 430 |
| 431 TEST_F(FileSystemOperationTest, TestCreateVeryLongName) { |
| 432 ScopedTempDir dir; |
| 433 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
| 434 #if defined(OS_WIN) |
| 435 FilePath dir_path(FilePath::kExtendedPathPrefix + dir.path().value()); |
| 436 #else |
| 437 FilePath dir_path = dir.path(); |
| 438 #endif |
| 439 |
| 440 // TODO(kkanetkar): Once each platform's limitations have been enforced |
| 441 // consider that in this test. Currently this test is for |
| 442 // windows primarily. |
| 443 const char kLongPathChar160[] = |
| 444 "012345678901234567890123456789012345678901234567890123456789" |
| 445 "012345678901234567890123456789012345678901234567890123456789" |
| 446 "0123456789012345678901234567890123456789"; |
| 447 |
| 448 FilePath dir1 = dir_path.AppendASCII(kLongPathChar160); |
| 449 |
| 450 FilePath dir2 = dir1.AppendASCII(kLongPathChar160); |
| 451 |
| 452 FilePath file = dir2.AppendASCII(kLongPathChar160); |
| 453 |
| 454 operation()->CreateDirectory(dir1, false, true); |
| 455 MessageLoop::current()->RunAllPending(); |
| 456 |
| 457 operation()->CreateDirectory(dir2, false, true); |
| 458 MessageLoop::current()->RunAllPending(); |
| 459 |
| 460 operation()->CreateFile(file, true); |
| 461 MessageLoop::current()->RunAllPending(); |
| 462 EXPECT_TRUE(file_util::PathExists(file)); |
| 463 // ScopedTempDir does not delete dir with long name since it does |
| 464 // not prefix \\?\. So Delete the long file here. |
| 465 // TODO(kkanetkat) Fix ScopedTempDir to work with extended paths. |
| 466 EXPECT_TRUE(file_util::Delete(dir1, true)); |
| 467 } |
| 468 |
431 TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileExists) { | 469 TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileExists) { |
432 // Already existing file and exclusive false. | 470 // Already existing file and exclusive false. |
433 ScopedTempDir dir; | 471 ScopedTempDir dir; |
434 ASSERT_TRUE(dir.CreateUniqueTempDir()); | 472 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
435 FilePath file; | 473 FilePath file; |
436 file_util::CreateTemporaryFileInDir(dir.path(), &file); | 474 file_util::CreateTemporaryFileInDir(dir.path(), &file); |
437 | 475 |
438 operation()->CreateFile(file, false); | 476 operation()->CreateFile(file, false); |
439 MessageLoop::current()->RunAllPending(); | 477 MessageLoop::current()->RunAllPending(); |
440 EXPECT_EQ(kFileOperationSucceeded, status()); | 478 EXPECT_EQ(kFileOperationSucceeded, status()); |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 | 759 |
722 // Check that its length is now 3 and that it contains only bits of test data. | 760 // Check that its length is now 3 and that it contains only bits of test data. |
723 EXPECT_TRUE(file_util::GetFileInfo(file, &info)); | 761 EXPECT_TRUE(file_util::GetFileInfo(file, &info)); |
724 EXPECT_EQ(length, info.size); | 762 EXPECT_EQ(length, info.size); |
725 EXPECT_EQ(length, file_util::ReadFile(file, data, length)); | 763 EXPECT_EQ(length, file_util::ReadFile(file, data, length)); |
726 for (int i = 0; i < length; ++i) | 764 for (int i = 0; i < length; ++i) |
727 EXPECT_EQ(test_data[i], data[i]); | 765 EXPECT_EQ(test_data[i], data[i]); |
728 } | 766 } |
729 | 767 |
730 } // namespace fileapi | 768 } // namespace fileapi |
OLD | NEW |