Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: content/browser/fileapi/obfuscated_file_util_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698