Chromium Code Reviews| Index: webkit/fileapi/obfuscated_file_system_file_util_unittest.cc |
| diff --git a/webkit/fileapi/obfuscated_file_system_file_util_unittest.cc b/webkit/fileapi/obfuscated_file_system_file_util_unittest.cc |
| index 6e61b9af2a578e369c309abb5957cd51c57e7871..5d20b92be0af0c2189a671b9498cabbe5d88e48f 100644 |
| --- a/webkit/fileapi/obfuscated_file_system_file_util_unittest.cc |
| +++ b/webkit/fileapi/obfuscated_file_system_file_util_unittest.cc |
| @@ -142,11 +142,32 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test { |
| obfuscated_file_system_file_util_.get()); |
| } |
| - FileSystemOperationContext* NewContext() { |
| - FileSystemOperationContext* context = test_helper_.NewOperationContext(); |
| + FileSystemOperationContext* NewContext(FileSystemTestOriginHelper* helper) { |
| + FileSystemOperationContext* context; |
| + if (helper) |
| + context = helper->NewOperationContext(); |
| + else |
| + context = test_helper_.NewOperationContext(); |
| + context->set_allowed_bytes_growth(1024); // Big enough for all tests. |
| return context; |
| } |
| + // This can only be used after SetUp has run and created data_dir_ and |
| + // obfuscated_file_system_file_util_. |
| + // Use this for tests which need to run in multiple origins; we need a test |
| + // helper per origin. |
| + FileSystemTestOriginHelper* NewHelper( |
| + const GURL& origin, fileapi::FileSystemType type) { |
| + FileSystemTestOriginHelper* helper = |
| + new FileSystemTestOriginHelper(origin, type); |
| + helper->SetUp(data_dir_.path(), |
| + false, // incognito |
| + false, // unlimited quota |
| + NULL, // quota::QuotaManagerProxy |
| + obfuscated_file_system_file_util_.get()); |
| + return helper; |
| + } |
| + |
| ObfuscatedFileSystemFileUtil* ofsfu() { |
| return obfuscated_file_system_file_util_.get(); |
| } |
| @@ -165,7 +186,7 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test { |
| void CheckFileAndCloseHandle( |
| const FilePath& virtual_path, PlatformFile file_handle) { |
| - scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| FilePath local_path; |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( |
| context.get(), virtual_path, &local_path)); |
| @@ -198,7 +219,7 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test { |
| base::PlatformFileInfo file_info1; |
| EXPECT_EQ(length, GetSize(data_path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
| context.get(), virtual_path, &file_info1, &data_path)); |
| EXPECT_EQ(data_path, local_path); |
| @@ -211,12 +232,12 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test { |
| EXPECT_EQ(length, file_info1.size); |
| EXPECT_LE(file_info0.last_modified, file_info1.last_modified); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( |
| context.get(), virtual_path, length * 2)); |
| EXPECT_EQ(length * 2, GetSize(data_path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( |
| context.get(), virtual_path, 1)); |
| EXPECT_EQ(1, GetSize(data_path)); |
| @@ -230,7 +251,7 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test { |
| std::set<FilePath::StringType>::const_iterator iter; |
| for (iter = files.begin(); iter != files.end(); ++iter) { |
| bool created = true; |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| ASSERT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->EnsureFileExists( |
| context.get(), root_path.Append(*iter), |
| @@ -238,7 +259,7 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test { |
| ASSERT_FALSE(created); |
| } |
| for (iter = directories.begin(); iter != directories.end(); ++iter) { |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), |
| root_path.Append(*iter))); |
| } |
| @@ -249,7 +270,7 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test { |
| std::set<FilePath::StringType>* files, |
| std::set<FilePath::StringType>* directories) { |
| scoped_ptr<FileSystemOperationContext> context; |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| std::vector<base::FileUtilProxy::Entry> entries; |
| EXPECT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->ReadDirectory(context.get(), root_path, &entries)); |
| @@ -266,7 +287,7 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test { |
| std::set<FilePath::StringType>::iterator iter; |
| for (iter = files->begin(); iter != files->end(); ++iter) { |
| bool created = false; |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| ASSERT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->EnsureFileExists( |
| context.get(), root_path.Append(*iter), &created)); |
| @@ -275,7 +296,7 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test { |
| for (iter = directories->begin(); iter != directories->end(); ++iter) { |
| bool exclusive = true; |
| bool recursive = false; |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->CreateDirectory( |
| context.get(), root_path.Append(*iter), exclusive, recursive)); |
| @@ -290,7 +311,7 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test { |
| scoped_ptr<FileSystemOperationContext> context; |
| std::vector<base::FileUtilProxy::Entry> entries; |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->ReadDirectory(context.get(), root_path, &entries)); |
| std::vector<base::FileUtilProxy::Entry>::iterator entry_iter; |
| @@ -314,13 +335,13 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test { |
| void TestTouchHelper(const FilePath& path) { |
| base::Time last_access_time = base::Time::Now(); // Ignored, so not tested. |
| base::Time last_modified_time = base::Time::Now(); |
| - scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->Touch( |
| context.get(), path, last_access_time, last_modified_time)); |
| FilePath local_path; |
| base::PlatformFileInfo file_info; |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
| context.get(), path, &file_info, &local_path)); |
| // We compare as time_t here to lower our resolution, to avoid false |
| @@ -328,12 +349,12 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test { |
| // representation and back. |
| EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| last_modified_time += base::TimeDelta::FromHours(1); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->Touch( |
| context.get(), path, last_access_time, last_modified_time)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
| context.get(), path, &file_info, &local_path)); |
| EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); |
| @@ -362,20 +383,20 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test { |
| scoped_ptr<FileSystemOperationContext> context; |
| if (overwrite) { |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->EnsureFileExists(context.get(), dest_path, &created)); |
| EXPECT_TRUE(created); |
| } |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->CopyInForeignFile(context.get(), src_path, dest_path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_TRUE(ofsfu()->PathExists(context.get(), dest_path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| base::PlatformFileInfo file_info; |
| FilePath data_path; |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
| @@ -402,7 +423,7 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCreateAndDeleteFile) { |
| base::PlatformFile file_handle = base::kInvalidPlatformFileValue; |
| bool created; |
| FilePath path = UTF8ToFilePath("fake/file"); |
| - scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; |
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| @@ -410,13 +431,13 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCreateAndDeleteFile) { |
| context.get(), path, file_flags, &file_handle, |
| &created)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| ofsfu()->DeleteFile(context.get(), path)); |
| path = UTF8ToFilePath("test file"); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| ASSERT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->CreateOrOpen( |
| context.get(), path, file_flags, &file_handle, &created)); |
| @@ -425,18 +446,18 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCreateAndDeleteFile) { |
| CheckFileAndCloseHandle(path, file_handle); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| FilePath local_path; |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( |
| context.get(), path, &local_path)); |
| EXPECT_TRUE(file_util::PathExists(local_path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->DeleteFile(context.get(), path)); |
| EXPECT_FALSE(file_util::PathExists(local_path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| bool exclusive = true; |
| bool recursive = true; |
| FilePath directory_path = UTF8ToFilePath("series/of/directories"); |
| @@ -444,7 +465,7 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCreateAndDeleteFile) { |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
| context.get(), directory_path, exclusive, recursive)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| file_handle = base::kInvalidPlatformFileValue; |
| ASSERT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->CreateOrOpen( |
| @@ -454,12 +475,12 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCreateAndDeleteFile) { |
| CheckFileAndCloseHandle(path, file_handle); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( |
| context.get(), path, &local_path)); |
| EXPECT_TRUE(file_util::PathExists(local_path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->DeleteFile(context.get(), path)); |
| EXPECT_FALSE(file_util::PathExists(local_path)); |
| @@ -468,47 +489,47 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCreateAndDeleteFile) { |
| TEST_F(ObfuscatedFileSystemFileUtilTest, TestTruncate) { |
| bool created = false; |
| FilePath path = UTF8ToFilePath("file"); |
| - scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| ofsfu()->Truncate(context.get(), path, 4)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| ASSERT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->EnsureFileExists(context.get(), path, &created)); |
| ASSERT_TRUE(created); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| FilePath local_path; |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( |
| context.get(), path, &local_path)); |
| EXPECT_EQ(0, GetSize(local_path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( |
| context.get(), path, 10)); |
| EXPECT_EQ(10, GetSize(local_path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( |
| context.get(), path, 1)); |
| EXPECT_EQ(1, GetSize(local_path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); |
| } |
| TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnsureFileExists) { |
| FilePath path = UTF8ToFilePath("fake/file"); |
| bool created = false; |
| - scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| ofsfu()->EnsureFileExists( |
| context.get(), path, &created)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| path = UTF8ToFilePath("test file"); |
| created = false; |
| ASSERT_EQ(base::PLATFORM_FILE_OK, |
| @@ -517,31 +538,31 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnsureFileExists) { |
| CheckFileAndCloseHandle(path, base::kInvalidPlatformFileValue); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| ASSERT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->EnsureFileExists(context.get(), path, &created)); |
| ASSERT_FALSE(created); |
| // Also test in a subdirectory. |
| path = UTF8ToFilePath("path/to/file.txt"); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| bool exclusive = true; |
| bool recursive = true; |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
| context.get(), path.DirName(), exclusive, recursive)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| ASSERT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->EnsureFileExists(context.get(), path, &created)); |
| ASSERT_TRUE(created); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); |
| } |
| TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) { |
| - scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| bool exclusive = false; |
| bool recursive = false; |
| @@ -549,37 +570,37 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) { |
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->CreateDirectory( |
| context.get(), path, exclusive, recursive)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| ofsfu()->DeleteSingleDirectory(context.get(), path)); |
| FilePath root = UTF8ToFilePath(""); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), root)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| exclusive = false; |
| recursive = true; |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
| context.get(), path, exclusive, recursive)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_FALSE(ofsfu()->IsDirectoryEmpty(context.get(), root)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path.DirName())); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_FALSE(ofsfu()->IsDirectoryEmpty(context.get(), path.DirName())); |
| // Can't remove a non-empty directory. |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, |
| ofsfu()->DeleteSingleDirectory(context.get(), path.DirName())); |
| @@ -592,27 +613,27 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) { |
| EXPECT_FALSE(file_info.is_symbolic_link); |
| // Same create again should succeed, since exclusive is false. |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
| context.get(), path, exclusive, recursive)); |
| exclusive = true; |
| recursive = true; |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( |
| context.get(), path, exclusive, recursive)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->DeleteSingleDirectory(context.get(), path)); |
| path = UTF8ToFilePath("foo/bop"); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), path)); |
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->GetFileInfo( |
| context.get(), path, &file_info, &local_path)); |
| @@ -622,9 +643,9 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) { |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
| context.get(), path, exclusive, recursive)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); |
| exclusive = true; |
| @@ -640,9 +661,9 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) { |
| path = UTF8ToFilePath("blah"); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); |
| exclusive = true; |
| @@ -650,9 +671,9 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) { |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
| context.get(), path, exclusive, recursive)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); |
| exclusive = true; |
| @@ -662,7 +683,7 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) { |
| } |
| TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadDirectory) { |
| - scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| bool exclusive = true; |
| bool recursive = true; |
| FilePath path = UTF8ToFilePath("directory/to/use"); |
| @@ -681,14 +702,14 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadRootWithEmptyString) { |
| TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadDirectoryOnFile) { |
| FilePath path = UTF8ToFilePath("file"); |
| - scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| bool created = false; |
| ASSERT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->EnsureFileExists(context.get(), path, &created)); |
| ASSERT_TRUE(created); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| std::vector<base::FileUtilProxy::Entry> entries; |
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| ofsfu()->ReadDirectory(context.get(), path, &entries)); |
| @@ -700,7 +721,7 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestTouch) { |
| FilePath path = UTF8ToFilePath("fake/file"); |
| base::Time last_access_time = base::Time::Now(); // Ignored, so not tested. |
| base::Time last_modified_time = base::Time::Now(); |
| - scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| ofsfu()->Touch( |
| context.get(), path, last_access_time, last_modified_time)); |
| @@ -712,22 +733,60 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestTouch) { |
| bool exclusive = true; |
| bool recursive = true; |
| path = UTF8ToFilePath("directory/to/use"); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
| context.get(), path, exclusive, recursive)); |
| TestTouchHelper(path); |
| } |
| +TEST_F(ObfuscatedFileSystemFileUtilTest, TestPathQuotas) { |
| + FilePath path = UTF8ToFilePath("fake/file"); |
| + base::Time last_access_time = base::Time::Now(); |
| + base::Time last_modified_time = base::Time::Now(); |
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| + |
| + // Touch will create a file if it's not there but its parent is. |
| + path = UTF8ToFilePath("file name"); |
| + context->set_allowed_bytes_growth(5); |
| + EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, |
| + ofsfu()->Touch( |
| + context.get(), path, last_access_time, last_modified_time)); |
| + context->set_allowed_bytes_growth(1024); |
| + EXPECT_EQ(base::PLATFORM_FILE_OK, |
| + ofsfu()->Touch( |
| + context.get(), path, last_access_time, last_modified_time)); |
| + int64 path_cost = ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path); |
| + EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth()); |
| + |
| + context->set_allowed_bytes_growth(1024); |
| + bool exclusive = true; |
| + bool recursive = true; |
| + path = UTF8ToFilePath("directory/to/use"); |
| + std::vector<FilePath::StringType> components; |
| + path.GetComponents(&components); |
| + path_cost = 0; |
| + for (std::vector<FilePath::StringType>::iterator iter = components.begin(); |
| + iter != components.end(); ++iter) { |
|
kinuko
2011/08/15 03:42:34
nit: indent
ericu
2011/08/15 23:47:10
4 spaces at a line wrap, two spaces for the interi
|
| + path_cost += ObfuscatedFileSystemFileUtil::ComputeFilePathCost( |
| + FilePath(*iter)); |
| + } |
| + context.reset(NewContext(NULL)); |
| + context->set_allowed_bytes_growth(1024); |
| + EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
| + context.get(), path, exclusive, recursive)); |
| + EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth()); |
| +} |
| + |
| TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileNotFound) { |
| FilePath source_path = UTF8ToFilePath("path0.txt"); |
| FilePath dest_path = UTF8ToFilePath("path1.txt"); |
| - scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| bool is_copy_not_move = false; |
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, |
| is_copy_not_move)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| is_copy_not_move = true; |
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, |
| @@ -735,14 +794,14 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileNotFound) { |
| source_path = UTF8ToFilePath("dir/dir/file"); |
| bool exclusive = true; |
| bool recursive = true; |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
| context.get(), source_path.DirName(), exclusive, recursive)); |
| is_copy_not_move = false; |
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, |
| is_copy_not_move)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| is_copy_not_move = true; |
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, |
| @@ -764,47 +823,47 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileSuccess) { |
| test_case.dest_path); |
| SCOPED_TRACE(testing::Message() << "\t cause_overwrite " << |
| test_case.cause_overwrite); |
| - scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| bool exclusive = false; |
| bool recursive = true; |
| FilePath source_path = UTF8ToFilePath(test_case.source_path); |
| FilePath dest_path = UTF8ToFilePath(test_case.dest_path); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
| context.get(), source_path.DirName(), exclusive, recursive)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( |
| context.get(), dest_path.DirName(), exclusive, recursive)); |
| bool created = false; |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| ASSERT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->EnsureFileExists(context.get(), source_path, &created)); |
| ASSERT_TRUE(created); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| ASSERT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->Truncate(context.get(), source_path, kSourceLength)); |
| if (test_case.cause_overwrite) { |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| created = false; |
| ASSERT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->EnsureFileExists(context.get(), dest_path, &created)); |
| ASSERT_TRUE(created); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| ASSERT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->Truncate(context.get(), dest_path, kDestLength)); |
| } |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CopyOrMoveFile(context.get(), |
| source_path, dest_path, test_case.is_copy_not_move)); |
| if (test_case.is_copy_not_move) { |
| base::PlatformFileInfo file_info; |
| FilePath local_path; |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( |
| context.get(), source_path, &file_info, &local_path)); |
| EXPECT_EQ(kSourceLength, file_info.size); |
| @@ -813,7 +872,7 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileSuccess) { |
| } else { |
| base::PlatformFileInfo file_info; |
| FilePath local_path; |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->GetFileInfo( |
| context.get(), source_path, &file_info, &local_path)); |
| } |
| @@ -834,7 +893,7 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyInForeignFile) { |
| } |
| TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnumerator) { |
| - scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| FilePath src_path = UTF8ToFilePath("source dir"); |
| bool exclusive = true; |
| bool recursive = false; |
| @@ -847,22 +906,22 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnumerator) { |
| FilePath dest_path = UTF8ToFilePath("destination dir"); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| ASSERT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->Copy(context.get(), src_path, dest_path)); |
| ValidateTestDirectory(dest_path, files, directories); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), src_path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), dest_path)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| recursive = true; |
| ASSERT_EQ(base::PLATFORM_FILE_OK, |
| ofsfu()->Delete(context.get(), dest_path, recursive)); |
| - context.reset(NewContext()); |
| + context.reset(NewContext(NULL)); |
| EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); |
| } |
| @@ -907,7 +966,7 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestMigration) { |
| #if defined(OS_WIN) |
| local_data_path = local_data_path.NormalizeWindowsPathSeparators(); |
| #endif |
| - scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| base::PlatformFileInfo ofsfu_file_info; |
| FilePath data_path; |
| SCOPED_TRACE(testing::Message() << "Path is " << test_case.path); |
| @@ -924,7 +983,7 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestMigration) { |
| ASSERT_TRUE(file_util::GetFileInfo(local_data_path, &platform_file_info)); |
| EXPECT_EQ(test_case.data_file_size, platform_file_info.size); |
| EXPECT_FALSE(platform_file_info.is_directory); |
| - scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| EXPECT_EQ(local_data_path, data_path); |
| EXPECT_EQ(platform_file_info.size, ofsfu_file_info.size); |
| EXPECT_FALSE(ofsfu_file_info.is_directory); |
| @@ -950,7 +1009,9 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestOriginEnumerator) { |
| GURL origin_url(record.origin_url); |
| origins_expected.insert(origin_url); |
| if (record.has_temporary) { |
| - scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| + scoped_ptr<FileSystemTestOriginHelper> helper( |
| + NewHelper(origin_url, kFileSystemTypeTemporary)); |
| + scoped_ptr<FileSystemOperationContext> context(NewContext(helper.get())); |
| context->set_src_origin_url(origin_url); |
| context->set_src_type(kFileSystemTypeTemporary); |
| bool created = false; |
| @@ -960,7 +1021,9 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestOriginEnumerator) { |
| EXPECT_TRUE(created); |
| } |
| if (record.has_persistent) { |
| - scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| + scoped_ptr<FileSystemTestOriginHelper> helper( |
| + NewHelper(origin_url, kFileSystemTypePersistent)); |
| + scoped_ptr<FileSystemOperationContext> context(NewContext(helper.get())); |
| context->set_src_origin_url(origin_url); |
| context->set_src_type(kFileSystemTypePersistent); |
| bool created = false; |