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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/files/file.h" | 11 #include "base/files/file.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/platform_file.h" | |
16 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
17 #include "content/browser/fileapi/mock_file_change_observer.h" | 16 #include "content/browser/fileapi/mock_file_change_observer.h" |
18 #include "content/public/test/async_file_test_helper.h" | 17 #include "content/public/test/async_file_test_helper.h" |
19 #include "content/public/test/mock_special_storage_policy.h" | 18 #include "content/public/test/mock_special_storage_policy.h" |
20 #include "content/public/test/sandbox_file_system_test_helper.h" | 19 #include "content/public/test/sandbox_file_system_test_helper.h" |
21 #include "content/public/test/test_file_system_context.h" | 20 #include "content/public/test/test_file_system_context.h" |
22 #include "content/test/fileapi_test_file_set.h" | 21 #include "content/test/fileapi_test_file_set.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "webkit/browser/fileapi/external_mount_points.h" | 23 #include "webkit/browser/fileapi/external_mount_points.h" |
25 #include "webkit/browser/fileapi/file_system_backend.h" | 24 #include "webkit/browser/fileapi/file_system_backend.h" |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 } | 314 } |
316 | 315 |
317 int64 PathCost(const FileSystemURL& url) { | 316 int64 PathCost(const FileSystemURL& url) { |
318 return ObfuscatedFileUtil::ComputeFilePathCost(url.path()); | 317 return ObfuscatedFileUtil::ComputeFilePathCost(url.path()); |
319 } | 318 } |
320 | 319 |
321 FileSystemURL CreateURL(const base::FilePath& path) { | 320 FileSystemURL CreateURL(const base::FilePath& path) { |
322 return sandbox_file_system_.CreateURL(path); | 321 return sandbox_file_system_.CreateURL(path); |
323 } | 322 } |
324 | 323 |
325 void CheckFileAndCloseHandle( | 324 void CheckFileAndCloseHandle(const FileSystemURL& url, base::File file) { |
326 const FileSystemURL& url, base::PlatformFile file_handle) { | |
327 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 325 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
328 base::FilePath local_path; | 326 base::FilePath local_path; |
329 EXPECT_EQ(base::File::FILE_OK, | 327 EXPECT_EQ(base::File::FILE_OK, |
330 ofu()->GetLocalFilePath(context.get(), url, &local_path)); | 328 ofu()->GetLocalFilePath(context.get(), url, &local_path)); |
331 | 329 |
332 base::File::Info file_info0; | 330 base::File::Info file_info0; |
333 base::FilePath data_path; | 331 base::FilePath data_path; |
334 EXPECT_EQ(base::File::FILE_OK, | 332 EXPECT_EQ(base::File::FILE_OK, |
335 ofu()->GetFileInfo(context.get(), url, &file_info0, &data_path)); | 333 ofu()->GetFileInfo(context.get(), url, &file_info0, &data_path)); |
336 EXPECT_EQ(data_path, local_path); | 334 EXPECT_EQ(data_path, local_path); |
337 EXPECT_TRUE(FileExists(data_path)); | 335 EXPECT_TRUE(FileExists(data_path)); |
338 EXPECT_EQ(0, GetSize(data_path)); | 336 EXPECT_EQ(0, GetSize(data_path)); |
339 | 337 |
340 const char data[] = "test data"; | 338 const char data[] = "test data"; |
341 const int length = arraysize(data) - 1; | 339 const int length = arraysize(data) - 1; |
342 | 340 |
343 if (base::kInvalidPlatformFileValue == file_handle) { | 341 if (!file.IsValid()) { |
344 base::File file(data_path, | 342 file.Initialize(data_path, |
345 base::File::FLAG_OPEN | base::File::FLAG_WRITE); | 343 base::File::FLAG_OPEN | base::File::FLAG_WRITE); |
346 ASSERT_TRUE(file.IsValid()); | 344 ASSERT_TRUE(file.IsValid()); |
347 EXPECT_FALSE(file.created()); | 345 EXPECT_FALSE(file.created()); |
348 file_handle = file.TakePlatformFile(); | |
349 } | 346 } |
350 ASSERT_EQ(length, base::WritePlatformFile(file_handle, 0, data, length)); | 347 ASSERT_EQ(length, file.Write(0, data, length)); |
351 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); | 348 file.Close(); |
352 | 349 |
353 base::File::Info file_info1; | 350 base::File::Info file_info1; |
354 EXPECT_EQ(length, GetSize(data_path)); | 351 EXPECT_EQ(length, GetSize(data_path)); |
355 context.reset(NewContext(NULL)); | 352 context.reset(NewContext(NULL)); |
356 EXPECT_EQ(base::File::FILE_OK, | 353 EXPECT_EQ(base::File::FILE_OK, |
357 ofu()->GetFileInfo(context.get(), url, &file_info1, &data_path)); | 354 ofu()->GetFileInfo(context.get(), url, &file_info1, &data_path)); |
358 EXPECT_EQ(data_path, local_path); | 355 EXPECT_EQ(data_path, local_path); |
359 | 356 |
360 EXPECT_FALSE(file_info0.is_directory); | 357 EXPECT_FALSE(file_info0.is_directory); |
361 EXPECT_FALSE(file_info1.is_directory); | 358 EXPECT_FALSE(file_info1.is_directory); |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 quota::QuotaStatusCode quota_status_; | 812 quota::QuotaStatusCode quota_status_; |
816 int64 usage_; | 813 int64 usage_; |
817 fileapi::MockFileChangeObserver change_observer_; | 814 fileapi::MockFileChangeObserver change_observer_; |
818 fileapi::ChangeObserverList change_observers_; | 815 fileapi::ChangeObserverList change_observers_; |
819 | 816 |
820 private: | 817 private: |
821 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtilTest); | 818 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtilTest); |
822 }; | 819 }; |
823 | 820 |
824 TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) { | 821 TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) { |
825 base::PlatformFile file_handle = base::kInvalidPlatformFileValue; | |
826 bool created; | |
827 FileSystemURL url = CreateURLFromUTF8("fake/file"); | 822 FileSystemURL url = CreateURLFromUTF8("fake/file"); |
828 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 823 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
829 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; | 824 int file_flags = base::File::FLAG_CREATE | base::File::FLAG_WRITE; |
830 | 825 |
831 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, | 826 base::File file = ofu()->CreateOrOpen(context.get(), url, file_flags); |
832 ofu()->CreateOrOpen(context.get(), url, file_flags, &file_handle, | 827 EXPECT_FALSE(file.IsValid()); |
833 &created)); | 828 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, file.error_details()); |
834 | 829 |
835 context.reset(NewContext(NULL)); | 830 context.reset(NewContext(NULL)); |
836 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, | 831 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, |
837 ofu()->DeleteFile(context.get(), url)); | 832 ofu()->DeleteFile(context.get(), url)); |
838 | 833 |
839 url = CreateURLFromUTF8("test file"); | 834 url = CreateURLFromUTF8("test file"); |
840 | 835 |
841 EXPECT_TRUE(change_observer()->HasNoChange()); | 836 EXPECT_TRUE(change_observer()->HasNoChange()); |
842 | 837 |
843 // Verify that file creation requires sufficient quota for the path. | 838 // Verify that file creation requires sufficient quota for the path. |
844 context.reset(NewContext(NULL)); | 839 context.reset(NewContext(NULL)); |
845 context->set_allowed_bytes_growth( | 840 context->set_allowed_bytes_growth( |
846 ObfuscatedFileUtil::ComputeFilePathCost(url.path()) - 1); | 841 ObfuscatedFileUtil::ComputeFilePathCost(url.path()) - 1); |
847 ASSERT_EQ(base::File::FILE_ERROR_NO_SPACE, | 842 file = ofu()->CreateOrOpen(context.get(), url, file_flags); |
848 ofu()->CreateOrOpen(context.get(), url, file_flags, | 843 EXPECT_FALSE(file.IsValid()); |
849 &file_handle, &created)); | 844 ASSERT_EQ(base::File::FILE_ERROR_NO_SPACE, file.error_details()); |
850 | 845 |
851 context.reset(NewContext(NULL)); | 846 context.reset(NewContext(NULL)); |
852 context->set_allowed_bytes_growth( | 847 context->set_allowed_bytes_growth( |
853 ObfuscatedFileUtil::ComputeFilePathCost(url.path())); | 848 ObfuscatedFileUtil::ComputeFilePathCost(url.path())); |
854 ASSERT_EQ(base::File::FILE_OK, | 849 file = ofu()->CreateOrOpen(context.get(), url, file_flags); |
855 ofu()->CreateOrOpen(context.get(), url, file_flags, &file_handle, | 850 EXPECT_TRUE(file.IsValid()); |
856 &created)); | 851 ASSERT_TRUE(file.created()); |
857 ASSERT_TRUE(created); | |
858 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | 852 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
859 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); | |
860 | 853 |
861 CheckFileAndCloseHandle(url, file_handle); | 854 CheckFileAndCloseHandle(url, file.Pass()); |
862 | 855 |
863 context.reset(NewContext(NULL)); | 856 context.reset(NewContext(NULL)); |
864 base::FilePath local_path; | 857 base::FilePath local_path; |
865 EXPECT_EQ(base::File::FILE_OK, | 858 EXPECT_EQ(base::File::FILE_OK, |
866 ofu()->GetLocalFilePath(context.get(), url, &local_path)); | 859 ofu()->GetLocalFilePath(context.get(), url, &local_path)); |
867 EXPECT_TRUE(base::PathExists(local_path)); | 860 EXPECT_TRUE(base::PathExists(local_path)); |
868 | 861 |
869 // Verify that deleting a file isn't stopped by zero quota, and that it frees | 862 // Verify that deleting a file isn't stopped by zero quota, and that it frees |
870 // up quote from its path. | 863 // up quote from its path. |
871 context.reset(NewContext(NULL)); | 864 context.reset(NewContext(NULL)); |
(...skipping 10 matching lines...) Expand all Loading... |
882 FileSystemURL directory_url = CreateURLFromUTF8( | 875 FileSystemURL directory_url = CreateURLFromUTF8( |
883 "series/of/directories"); | 876 "series/of/directories"); |
884 url = FileSystemURLAppendUTF8(directory_url, "file name"); | 877 url = FileSystemURLAppendUTF8(directory_url, "file name"); |
885 EXPECT_EQ(base::File::FILE_OK, | 878 EXPECT_EQ(base::File::FILE_OK, |
886 ofu()->CreateDirectory(context.get(), directory_url, exclusive, | 879 ofu()->CreateDirectory(context.get(), directory_url, exclusive, |
887 recursive)); | 880 recursive)); |
888 // The oepration created 3 directories recursively. | 881 // The oepration created 3 directories recursively. |
889 EXPECT_EQ(3, change_observer()->get_and_reset_create_directory_count()); | 882 EXPECT_EQ(3, change_observer()->get_and_reset_create_directory_count()); |
890 | 883 |
891 context.reset(NewContext(NULL)); | 884 context.reset(NewContext(NULL)); |
892 file_handle = base::kInvalidPlatformFileValue; | 885 file = ofu()->CreateOrOpen(context.get(), url, file_flags); |
893 ASSERT_EQ(base::File::FILE_OK, | 886 ASSERT_TRUE(file.IsValid()); |
894 ofu()->CreateOrOpen(context.get(), url, file_flags, &file_handle, | 887 ASSERT_TRUE(file.created()); |
895 &created)); | |
896 ASSERT_TRUE(created); | |
897 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | 888 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
898 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); | |
899 | 889 |
900 CheckFileAndCloseHandle(url, file_handle); | 890 CheckFileAndCloseHandle(url, file.Pass()); |
901 | 891 |
902 context.reset(NewContext(NULL)); | 892 context.reset(NewContext(NULL)); |
903 EXPECT_EQ(base::File::FILE_OK, | 893 EXPECT_EQ(base::File::FILE_OK, |
904 ofu()->GetLocalFilePath(context.get(), url, &local_path)); | 894 ofu()->GetLocalFilePath(context.get(), url, &local_path)); |
905 EXPECT_TRUE(base::PathExists(local_path)); | 895 EXPECT_TRUE(base::PathExists(local_path)); |
906 | 896 |
907 context.reset(NewContext(NULL)); | 897 context.reset(NewContext(NULL)); |
908 EXPECT_EQ(base::File::FILE_OK, ofu()->DeleteFile(context.get(), url)); | 898 EXPECT_EQ(base::File::FILE_OK, ofu()->DeleteFile(context.get(), url)); |
909 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 899 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
910 EXPECT_FALSE(base::PathExists(local_path)); | 900 EXPECT_FALSE(base::PathExists(local_path)); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 EXPECT_TRUE(change_observer()->HasNoChange()); | 1015 EXPECT_TRUE(change_observer()->HasNoChange()); |
1026 | 1016 |
1027 context.reset(NewContext(NULL)); | 1017 context.reset(NewContext(NULL)); |
1028 context->set_allowed_bytes_growth( | 1018 context->set_allowed_bytes_growth( |
1029 ObfuscatedFileUtil::ComputeFilePathCost(url.path())); | 1019 ObfuscatedFileUtil::ComputeFilePathCost(url.path())); |
1030 ASSERT_EQ(base::File::FILE_OK, | 1020 ASSERT_EQ(base::File::FILE_OK, |
1031 ofu()->EnsureFileExists(context.get(), url, &created)); | 1021 ofu()->EnsureFileExists(context.get(), url, &created)); |
1032 ASSERT_TRUE(created); | 1022 ASSERT_TRUE(created); |
1033 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | 1023 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
1034 | 1024 |
1035 CheckFileAndCloseHandle(url, base::kInvalidPlatformFileValue); | 1025 CheckFileAndCloseHandle(url, base::File()); |
1036 | 1026 |
1037 context.reset(NewContext(NULL)); | 1027 context.reset(NewContext(NULL)); |
1038 ASSERT_EQ(base::File::FILE_OK, | 1028 ASSERT_EQ(base::File::FILE_OK, |
1039 ofu()->EnsureFileExists(context.get(), url, &created)); | 1029 ofu()->EnsureFileExists(context.get(), url, &created)); |
1040 ASSERT_FALSE(created); | 1030 ASSERT_FALSE(created); |
1041 EXPECT_TRUE(change_observer()->HasNoChange()); | 1031 EXPECT_TRUE(change_observer()->HasNoChange()); |
1042 | 1032 |
1043 // Also test in a subdirectory. | 1033 // Also test in a subdirectory. |
1044 url = CreateURLFromUTF8("path/to/file.txt"); | 1034 url = CreateURLFromUTF8("path/to/file.txt"); |
1045 context.reset(NewContext(NULL)); | 1035 context.reset(NewContext(NULL)); |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1713 EXPECT_EQ(expected_quota, SizeInUsageFile()); | 1703 EXPECT_EQ(expected_quota, SizeInUsageFile()); |
1714 EXPECT_EQ(expected_quota, SizeByQuotaUtil()); | 1704 EXPECT_EQ(expected_quota, SizeByQuotaUtil()); |
1715 EXPECT_EQ(expected_quota, usage()); | 1705 EXPECT_EQ(expected_quota, usage()); |
1716 } | 1706 } |
1717 | 1707 |
1718 TEST_F(ObfuscatedFileUtilTest, TestInconsistency) { | 1708 TEST_F(ObfuscatedFileUtilTest, TestInconsistency) { |
1719 const FileSystemURL kPath1 = CreateURLFromUTF8("hoge"); | 1709 const FileSystemURL kPath1 = CreateURLFromUTF8("hoge"); |
1720 const FileSystemURL kPath2 = CreateURLFromUTF8("fuga"); | 1710 const FileSystemURL kPath2 = CreateURLFromUTF8("fuga"); |
1721 | 1711 |
1722 scoped_ptr<FileSystemOperationContext> context; | 1712 scoped_ptr<FileSystemOperationContext> context; |
1723 base::PlatformFile file; | |
1724 base::File::Info file_info; | 1713 base::File::Info file_info; |
1725 base::FilePath data_path; | 1714 base::FilePath data_path; |
1726 bool created = false; | 1715 bool created = false; |
1727 | 1716 |
1728 // Create a non-empty file. | 1717 // Create a non-empty file. |
1729 context.reset(NewContext(NULL)); | 1718 context.reset(NewContext(NULL)); |
1730 EXPECT_EQ(base::File::FILE_OK, | 1719 EXPECT_EQ(base::File::FILE_OK, |
1731 ofu()->EnsureFileExists(context.get(), kPath1, &created)); | 1720 ofu()->EnsureFileExists(context.get(), kPath1, &created)); |
1732 EXPECT_TRUE(created); | 1721 EXPECT_TRUE(created); |
1733 context.reset(NewContext(NULL)); | 1722 context.reset(NewContext(NULL)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1774 | 1763 |
1775 // Copy from sound |kPath1| to broken |kPath2|. | 1764 // Copy from sound |kPath1| to broken |kPath2|. |
1776 context.reset(NewContext(NULL)); | 1765 context.reset(NewContext(NULL)); |
1777 EXPECT_EQ(base::File::FILE_OK, | 1766 EXPECT_EQ(base::File::FILE_OK, |
1778 ofu()->CopyOrMoveFile(context.get(), kPath1, kPath2, | 1767 ofu()->CopyOrMoveFile(context.get(), kPath1, kPath2, |
1779 FileSystemOperation::OPTION_NONE, | 1768 FileSystemOperation::OPTION_NONE, |
1780 true /* copy */)); | 1769 true /* copy */)); |
1781 | 1770 |
1782 ofu()->DestroyDirectoryDatabase(origin(), type_string()); | 1771 ofu()->DestroyDirectoryDatabase(origin(), type_string()); |
1783 context.reset(NewContext(NULL)); | 1772 context.reset(NewContext(NULL)); |
1784 EXPECT_EQ(base::File::FILE_OK, | 1773 base::File file = |
1785 ofu()->CreateOrOpen( | 1774 ofu()->CreateOrOpen(context.get(), kPath1, |
1786 context.get(), kPath1, | 1775 base::File::FLAG_READ | base::File::FLAG_CREATE); |
1787 base::PLATFORM_FILE_READ | base::PLATFORM_FILE_CREATE, | 1776 EXPECT_TRUE(file.IsValid()); |
1788 &file, &created)); | 1777 EXPECT_TRUE(file.created()); |
1789 EXPECT_TRUE(created); | |
1790 | 1778 |
1791 base::File base_file(file); | 1779 EXPECT_TRUE(file.GetInfo(&file_info)); |
1792 EXPECT_TRUE(base_file.GetInfo(&file_info)); | |
1793 EXPECT_EQ(0, file_info.size); | 1780 EXPECT_EQ(0, file_info.size); |
1794 } | 1781 } |
1795 | 1782 |
1796 TEST_F(ObfuscatedFileUtilTest, TestIncompleteDirectoryReading) { | 1783 TEST_F(ObfuscatedFileUtilTest, TestIncompleteDirectoryReading) { |
1797 const FileSystemURL kPath[] = { | 1784 const FileSystemURL kPath[] = { |
1798 CreateURLFromUTF8("foo"), | 1785 CreateURLFromUTF8("foo"), |
1799 CreateURLFromUTF8("bar"), | 1786 CreateURLFromUTF8("bar"), |
1800 CreateURLFromUTF8("baz") | 1787 CreateURLFromUTF8("baz") |
1801 }; | 1788 }; |
1802 const FileSystemURL empty_path = CreateURL(base::FilePath()); | 1789 const FileSystemURL empty_path = CreateURL(base::FilePath()); |
(...skipping 27 matching lines...) Expand all Loading... |
1830 | 1817 |
1831 TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForCreation) { | 1818 TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForCreation) { |
1832 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 1819 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
1833 const FileSystemURL dir_url = CreateURLFromUTF8("foo_dir"); | 1820 const FileSystemURL dir_url = CreateURLFromUTF8("foo_dir"); |
1834 | 1821 |
1835 // Create working directory. | 1822 // Create working directory. |
1836 EXPECT_EQ(base::File::FILE_OK, | 1823 EXPECT_EQ(base::File::FILE_OK, |
1837 ofu()->CreateDirectory(context.get(), dir_url, false, false)); | 1824 ofu()->CreateDirectory(context.get(), dir_url, false, false)); |
1838 | 1825 |
1839 // EnsureFileExists, create case. | 1826 // EnsureFileExists, create case. |
1840 FileSystemURL url(FileSystemURLAppendUTF8( | 1827 FileSystemURL url(FileSystemURLAppendUTF8(dir_url, "EnsureFileExists_file")); |
1841 dir_url, "EnsureFileExists_file")); | |
1842 bool created = false; | 1828 bool created = false; |
1843 ClearTimestamp(dir_url); | 1829 ClearTimestamp(dir_url); |
1844 context.reset(NewContext(NULL)); | 1830 context.reset(NewContext(NULL)); |
1845 EXPECT_EQ(base::File::FILE_OK, | 1831 EXPECT_EQ(base::File::FILE_OK, |
1846 ofu()->EnsureFileExists(context.get(), url, &created)); | 1832 ofu()->EnsureFileExists(context.get(), url, &created)); |
1847 EXPECT_TRUE(created); | 1833 EXPECT_TRUE(created); |
1848 EXPECT_NE(base::Time(), GetModifiedTime(dir_url)); | 1834 EXPECT_NE(base::Time(), GetModifiedTime(dir_url)); |
1849 | 1835 |
1850 // non create case. | 1836 // non create case. |
1851 created = true; | 1837 created = true; |
(...skipping 11 matching lines...) Expand all Loading... |
1863 ofu()->CreateDirectory(context.get(), url, false, false)); | 1849 ofu()->CreateDirectory(context.get(), url, false, false)); |
1864 | 1850 |
1865 ClearTimestamp(dir_url); | 1851 ClearTimestamp(dir_url); |
1866 context.reset(NewContext(NULL)); | 1852 context.reset(NewContext(NULL)); |
1867 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_FILE, | 1853 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_FILE, |
1868 ofu()->EnsureFileExists(context.get(), url, &created)); | 1854 ofu()->EnsureFileExists(context.get(), url, &created)); |
1869 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url)); | 1855 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url)); |
1870 | 1856 |
1871 // CreateOrOpen, create case. | 1857 // CreateOrOpen, create case. |
1872 url = FileSystemURLAppendUTF8(dir_url, "CreateOrOpen_file"); | 1858 url = FileSystemURLAppendUTF8(dir_url, "CreateOrOpen_file"); |
1873 base::PlatformFile file_handle = base::kInvalidPlatformFileValue; | |
1874 created = false; | |
1875 ClearTimestamp(dir_url); | 1859 ClearTimestamp(dir_url); |
1876 context.reset(NewContext(NULL)); | 1860 context.reset(NewContext(NULL)); |
1877 EXPECT_EQ(base::File::FILE_OK, | 1861 base::File file = |
1878 ofu()->CreateOrOpen( | 1862 ofu()->CreateOrOpen(context.get(), url, |
1879 context.get(), url, | 1863 base::File::FLAG_CREATE | base::File::FLAG_WRITE); |
1880 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE, | 1864 |
1881 &file_handle, &created)); | 1865 EXPECT_TRUE(file.IsValid()); |
1882 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); | 1866 EXPECT_TRUE(file.created()); |
1883 EXPECT_TRUE(created); | 1867 file.Close(); |
1884 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); | |
1885 EXPECT_NE(base::Time(), GetModifiedTime(dir_url)); | 1868 EXPECT_NE(base::Time(), GetModifiedTime(dir_url)); |
1886 | 1869 |
1887 // open case. | 1870 // open case. |
1888 file_handle = base::kInvalidPlatformFileValue; | |
1889 created = true; | |
1890 ClearTimestamp(dir_url); | 1871 ClearTimestamp(dir_url); |
1891 context.reset(NewContext(NULL)); | 1872 context.reset(NewContext(NULL)); |
1892 EXPECT_EQ(base::File::FILE_OK, | 1873 file = ofu()->CreateOrOpen(context.get(), url, |
1893 ofu()->CreateOrOpen( | 1874 base::File::FLAG_OPEN | base::File::FLAG_WRITE); |
1894 context.get(), url, | 1875 EXPECT_TRUE(file.IsValid()); |
1895 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE, | 1876 EXPECT_FALSE(file.created()); |
1896 &file_handle, &created)); | 1877 file.Close(); |
1897 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); | |
1898 EXPECT_FALSE(created); | |
1899 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); | |
1900 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url)); | 1878 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url)); |
1901 | 1879 |
1902 // fail case | 1880 // fail case |
1903 file_handle = base::kInvalidPlatformFileValue; | |
1904 ClearTimestamp(dir_url); | 1881 ClearTimestamp(dir_url); |
1905 context.reset(NewContext(NULL)); | 1882 context.reset(NewContext(NULL)); |
1906 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, | 1883 file = ofu()->CreateOrOpen(context.get(), url, |
1907 ofu()->CreateOrOpen( | 1884 base::File::FLAG_CREATE | base::File::FLAG_WRITE); |
1908 context.get(), url, | 1885 EXPECT_FALSE(file.IsValid()); |
1909 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE, | 1886 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, file.error_details()); |
1910 &file_handle, &created)); | |
1911 EXPECT_EQ(base::kInvalidPlatformFileValue, file_handle); | |
1912 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url)); | 1887 EXPECT_EQ(base::Time(), GetModifiedTime(dir_url)); |
1913 | 1888 |
1914 // CreateDirectory, create case. | 1889 // CreateDirectory, create case. |
1915 // Creating CreateDirectory_dir and CreateDirectory_dir/subdir. | 1890 // Creating CreateDirectory_dir and CreateDirectory_dir/subdir. |
1916 url = FileSystemURLAppendUTF8(dir_url, "CreateDirectory_dir"); | 1891 url = FileSystemURLAppendUTF8(dir_url, "CreateDirectory_dir"); |
1917 FileSystemURL subdir_url(FileSystemURLAppendUTF8(url, "subdir")); | 1892 FileSystemURL subdir_url(FileSystemURLAppendUTF8(url, "subdir")); |
1918 ClearTimestamp(dir_url); | 1893 ClearTimestamp(dir_url); |
1919 context.reset(NewContext(NULL)); | 1894 context.reset(NewContext(NULL)); |
1920 EXPECT_EQ(base::File::FILE_OK, | 1895 EXPECT_EQ(base::File::FILE_OK, |
1921 ofu()->CreateDirectory(context.get(), subdir_url, | 1896 ofu()->CreateDirectory(context.get(), subdir_url, |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2360 file)); | 2335 file)); |
2361 ASSERT_EQ(1140, ComputeTotalFileSize()); | 2336 ASSERT_EQ(1140, ComputeTotalFileSize()); |
2362 | 2337 |
2363 ASSERT_EQ(base::File::FILE_OK, | 2338 ASSERT_EQ(base::File::FILE_OK, |
2364 AsyncFileTestHelper::Remove( | 2339 AsyncFileTestHelper::Remove( |
2365 file_system_context(), dir, true /* recursive */)); | 2340 file_system_context(), dir, true /* recursive */)); |
2366 ASSERT_EQ(0, ComputeTotalFileSize()); | 2341 ASSERT_EQ(0, ComputeTotalFileSize()); |
2367 } | 2342 } |
2368 | 2343 |
2369 TEST_F(ObfuscatedFileUtilTest, TestQuotaOnOpen) { | 2344 TEST_F(ObfuscatedFileUtilTest, TestQuotaOnOpen) { |
2370 FileSystemURL file(CreateURLFromUTF8("file")); | 2345 FileSystemURL url(CreateURLFromUTF8("file")); |
2371 base::PlatformFile file_handle; | 2346 |
2372 bool created; | 2347 bool created; |
2373 | |
2374 // Creating a file. | 2348 // Creating a file. |
2375 ASSERT_EQ(base::File::FILE_OK, | 2349 ASSERT_EQ(base::File::FILE_OK, |
2376 ofu()->EnsureFileExists( | 2350 ofu()->EnsureFileExists( |
2377 AllowUsageIncrease(PathCost(file))->context(), | 2351 AllowUsageIncrease(PathCost(url))->context(), |
2378 file, &created)); | 2352 url, &created)); |
2379 ASSERT_TRUE(created); | 2353 ASSERT_TRUE(created); |
2380 ASSERT_EQ(0, ComputeTotalFileSize()); | 2354 ASSERT_EQ(0, ComputeTotalFileSize()); |
2381 | 2355 |
2382 // Opening it, which shouldn't change the usage. | 2356 // Opening it, which shouldn't change the usage. |
2383 ASSERT_EQ(base::File::FILE_OK, | 2357 base::File file = |
2384 ofu()->CreateOrOpen( | 2358 ofu()->CreateOrOpen(AllowUsageIncrease(0)->context(), url, |
2385 AllowUsageIncrease(0)->context(), file, | 2359 base::File::FLAG_OPEN | base::File::FLAG_WRITE); |
2386 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE, | 2360 ASSERT_TRUE(file.IsValid()); |
2387 &file_handle, &created)); | |
2388 ASSERT_EQ(0, ComputeTotalFileSize()); | 2361 ASSERT_EQ(0, ComputeTotalFileSize()); |
2389 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); | 2362 file.Close(); |
2390 | 2363 |
2391 const int length = 33; | 2364 const int length = 33; |
2392 ASSERT_EQ(base::File::FILE_OK, | 2365 ASSERT_EQ(base::File::FILE_OK, |
2393 ofu()->Truncate( | 2366 ofu()->Truncate( |
2394 AllowUsageIncrease(length)->context(), file, length)); | 2367 AllowUsageIncrease(length)->context(), url, length)); |
2395 ASSERT_EQ(length, ComputeTotalFileSize()); | 2368 ASSERT_EQ(length, ComputeTotalFileSize()); |
2396 | 2369 |
2397 // Opening it with CREATE_ALWAYS flag, which should truncate the file size. | 2370 // Opening it with CREATE_ALWAYS flag, which should truncate the file size. |
2398 ASSERT_EQ(base::File::FILE_OK, | 2371 file = ofu()->CreateOrOpen( |
2399 ofu()->CreateOrOpen( | 2372 AllowUsageIncrease(-length)->context(), url, |
2400 AllowUsageIncrease(-length)->context(), file, | 2373 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); |
2401 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE, | 2374 ASSERT_TRUE(file.IsValid()); |
2402 &file_handle, &created)); | |
2403 ASSERT_EQ(0, ComputeTotalFileSize()); | 2375 ASSERT_EQ(0, ComputeTotalFileSize()); |
2404 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); | 2376 file.Close(); |
2405 | 2377 |
2406 // Extending the file again. | 2378 // Extending the file again. |
2407 ASSERT_EQ(base::File::FILE_OK, | 2379 ASSERT_EQ(base::File::FILE_OK, |
2408 ofu()->Truncate( | 2380 ofu()->Truncate( |
2409 AllowUsageIncrease(length)->context(), file, length)); | 2381 AllowUsageIncrease(length)->context(), url, length)); |
2410 ASSERT_EQ(length, ComputeTotalFileSize()); | 2382 ASSERT_EQ(length, ComputeTotalFileSize()); |
2411 | 2383 |
2412 // Opening it with TRUNCATED flag, which should truncate the file size. | 2384 // Opening it with TRUNCATED flag, which should truncate the file size. |
2413 ASSERT_EQ(base::File::FILE_OK, | 2385 file = ofu()->CreateOrOpen( |
2414 ofu()->CreateOrOpen( | 2386 AllowUsageIncrease(-length)->context(), url, |
2415 AllowUsageIncrease(-length)->context(), file, | 2387 base::File::FLAG_OPEN_TRUNCATED | base::File::FLAG_WRITE); |
2416 base::PLATFORM_FILE_OPEN_TRUNCATED | base::PLATFORM_FILE_WRITE, | 2388 ASSERT_TRUE(file.IsValid()); |
2417 &file_handle, &created)); | |
2418 ASSERT_EQ(0, ComputeTotalFileSize()); | 2389 ASSERT_EQ(0, ComputeTotalFileSize()); |
2419 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); | 2390 file.Close(); |
2420 } | 2391 } |
2421 | 2392 |
2422 TEST_F(ObfuscatedFileUtilTest, MaybeDropDatabasesAliveCase) { | 2393 TEST_F(ObfuscatedFileUtilTest, MaybeDropDatabasesAliveCase) { |
2423 MaybeDropDatabasesAliveCaseTestBody(); | 2394 MaybeDropDatabasesAliveCaseTestBody(); |
2424 } | 2395 } |
2425 | 2396 |
2426 TEST_F(ObfuscatedFileUtilTest, MaybeDropDatabasesAlreadyDeletedCase) { | 2397 TEST_F(ObfuscatedFileUtilTest, MaybeDropDatabasesAlreadyDeletedCase) { |
2427 MaybeDropDatabasesAlreadyDeletedCaseTestBody(); | 2398 MaybeDropDatabasesAlreadyDeletedCaseTestBody(); |
2428 } | 2399 } |
2429 | 2400 |
2430 TEST_F(ObfuscatedFileUtilTest, DestroyDirectoryDatabase_Isolated) { | 2401 TEST_F(ObfuscatedFileUtilTest, DestroyDirectoryDatabase_Isolated) { |
2431 DestroyDirectoryDatabase_IsolatedTestBody(); | 2402 DestroyDirectoryDatabase_IsolatedTestBody(); |
2432 } | 2403 } |
2433 | 2404 |
2434 TEST_F(ObfuscatedFileUtilTest, GetDirectoryDatabase_Isolated) { | 2405 TEST_F(ObfuscatedFileUtilTest, GetDirectoryDatabase_Isolated) { |
2435 GetDirectoryDatabase_IsolatedTestBody(); | 2406 GetDirectoryDatabase_IsolatedTestBody(); |
2436 } | 2407 } |
2437 | 2408 |
2438 TEST_F(ObfuscatedFileUtilTest, MigrationBackFromIsolated) { | 2409 TEST_F(ObfuscatedFileUtilTest, MigrationBackFromIsolated) { |
2439 MigrationBackFromIsolatedTestBody(); | 2410 MigrationBackFromIsolatedTestBody(); |
2440 } | 2411 } |
2441 | 2412 |
2442 TEST_F(ObfuscatedFileUtilTest, OpenPathInNonDirectory) { | 2413 TEST_F(ObfuscatedFileUtilTest, OpenPathInNonDirectory) { |
2443 FileSystemURL file(CreateURLFromUTF8("file")); | 2414 FileSystemURL url(CreateURLFromUTF8("file")); |
2444 FileSystemURL path_in_file(CreateURLFromUTF8("file/file")); | 2415 FileSystemURL path_in_file(CreateURLFromUTF8("file/file")); |
2445 bool created; | 2416 bool created; |
2446 | 2417 |
2447 ASSERT_EQ(base::File::FILE_OK, | 2418 ASSERT_EQ(base::File::FILE_OK, |
2448 ofu()->EnsureFileExists(UnlimitedContext().get(), file, &created)); | 2419 ofu()->EnsureFileExists(UnlimitedContext().get(), url, &created)); |
2449 ASSERT_TRUE(created); | 2420 ASSERT_TRUE(created); |
2450 | 2421 |
2451 created = false; | 2422 int file_flags = base::File::FLAG_CREATE | base::File::FLAG_WRITE; |
2452 base::PlatformFile file_handle = base::kInvalidPlatformFileValue; | 2423 base::File file = |
2453 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; | 2424 ofu()->CreateOrOpen(UnlimitedContext().get(), path_in_file, file_flags); |
2454 ASSERT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, | 2425 ASSERT_FALSE(file.IsValid()); |
2455 ofu()->CreateOrOpen(UnlimitedContext().get(), | 2426 ASSERT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, file.error_details()); |
2456 path_in_file, | |
2457 file_flags, | |
2458 &file_handle, | |
2459 &created)); | |
2460 ASSERT_FALSE(created); | |
2461 ASSERT_EQ(base::kInvalidPlatformFileValue, file_handle); | |
2462 | 2427 |
2463 ASSERT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, | 2428 ASSERT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, |
2464 ofu()->CreateDirectory(UnlimitedContext().get(), | 2429 ofu()->CreateDirectory(UnlimitedContext().get(), |
2465 path_in_file, | 2430 path_in_file, |
2466 false /* exclusive */, | 2431 false /* exclusive */, |
2467 false /* recursive */)); | 2432 false /* recursive */)); |
2468 } | 2433 } |
2469 | 2434 |
2470 TEST_F(ObfuscatedFileUtilTest, CreateDirectory_NotADirectoryInRecursive) { | 2435 TEST_F(ObfuscatedFileUtilTest, CreateDirectory_NotADirectoryInRecursive) { |
2471 FileSystemURL file(CreateURLFromUTF8("file")); | 2436 FileSystemURL file(CreateURLFromUTF8("file")); |
(...skipping 12 matching lines...) Expand all Loading... |
2484 false /* exclusive */, | 2449 false /* exclusive */, |
2485 true /* recursive */)); | 2450 true /* recursive */)); |
2486 ASSERT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, | 2451 ASSERT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, |
2487 ofu()->CreateDirectory(UnlimitedContext().get(), | 2452 ofu()->CreateDirectory(UnlimitedContext().get(), |
2488 path_in_file_in_file, | 2453 path_in_file_in_file, |
2489 false /* exclusive */, | 2454 false /* exclusive */, |
2490 true /* recursive */)); | 2455 true /* recursive */)); |
2491 } | 2456 } |
2492 | 2457 |
2493 } // namespace content | 2458 } // namespace content |
OLD | NEW |