diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-27 01:53:09 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-27 01:53:09 +0000 |
commit | 949f25a052e09392ef70b75bcda422dc13eeef45 (patch) | |
tree | 135512e13da7e59d8171d41f2f1ca48bb58611a8 /webkit/fileapi/isolated_file_util_unittest.cc | |
parent | 967dcfe12bf6fb2939407e9d883efb687ac5c031 (diff) | |
download | chromium_src-949f25a052e09392ef70b75bcda422dc13eeef45.zip chromium_src-949f25a052e09392ef70b75bcda422dc13eeef45.tar.gz chromium_src-949f25a052e09392ef70b75bcda422dc13eeef45.tar.bz2 |
Reduce the number of CrackFileSystemURL
- crack the filesystem URL as soon as we get it in FileAPIMessageFilter
- introduce a new class FileSystemURL for cracked URL information and use it everywhere
- deprecate FileSystemPath (this used to serve the similar role for *FileUtil classes)
Mechanical changes only except for fileapi_message_filter.cc and file_system_operation.cc.
This change reduces the # of CrackFileSystemURL roughly from 3~4 to 1 for each FileSystem operation.
BUG=none
TEST=existing tests
Review URL: https://chromiumcodereview.appspot.com/10566002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144368 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/isolated_file_util_unittest.cc')
-rw-r--r-- | webkit/fileapi/isolated_file_util_unittest.cc | 106 |
1 files changed, 53 insertions, 53 deletions
diff --git a/webkit/fileapi/isolated_file_util_unittest.cc b/webkit/fileapi/isolated_file_util_unittest.cc index 29f2cd5..fb54edd 100644 --- a/webkit/fileapi/isolated_file_util_unittest.cc +++ b/webkit/fileapi/isolated_file_util_unittest.cc @@ -99,38 +99,38 @@ class IsolatedFileUtilTest : public testing::Test { NormalizePathSeparators(); } - FileSystemPath GetFileSystemPath(const FilePath& path) const { + FileSystemURL GetFileSystemURL(const FilePath& path) const { FilePath virtual_path = isolated_context()->CreateVirtualPath( filesystem_id(), path); - return FileSystemPath(GURL("http://example.com"), - kFileSystemTypeIsolated, - virtual_path); + return FileSystemURL(GURL("http://example.com"), + kFileSystemTypeIsolated, + virtual_path); } - FileSystemPath GetOtherFileSystemPath(const FilePath& path) { - return other_file_util_helper_.CreatePath(path); + FileSystemURL GetOtherFileSystemURL(const FilePath& path) { + return other_file_util_helper_.CreateURL(path); } void VerifyFilesHaveSameContent(FileSystemFileUtil* file_util1, FileSystemFileUtil* file_util2, - const FileSystemPath& path1, - const FileSystemPath& path2) { + const FileSystemURL& url1, + const FileSystemURL& url2) { scoped_ptr<FileSystemOperationContext> context; - // Get the file info for path1. + // Get the file info for url1. base::PlatformFileInfo info1; FilePath platform_path1; context.reset(new FileSystemOperationContext(file_system_context())); ASSERT_EQ(base::PLATFORM_FILE_OK, - file_util1->GetFileInfo(context.get(), path1, + file_util1->GetFileInfo(context.get(), url1, &info1, &platform_path1)); - // Get the file info for path2. + // Get the file info for url2. base::PlatformFileInfo info2; FilePath platform_path2; context.reset(new FileSystemOperationContext(file_system_context())); ASSERT_EQ(base::PLATFORM_FILE_OK, - file_util2->GetFileInfo(context.get(), path2, + file_util2->GetFileInfo(context.get(), url2, &info2, &platform_path2)); // See if file info matches with the other one. @@ -147,8 +147,8 @@ class IsolatedFileUtilTest : public testing::Test { void VerifyDirectoriesHaveSameContent(FileSystemFileUtil* file_util1, FileSystemFileUtil* file_util2, - const FileSystemPath& root1, - const FileSystemPath& root2) { + const FileSystemURL& root1, + const FileSystemURL& root2) { scoped_ptr<FileSystemOperationContext> context; scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum1; @@ -170,17 +170,17 @@ class IsolatedFileUtilTest : public testing::Test { context.get(), root2, true /* recursive */)); while (!(current = file_enum2->Next()).empty()) { - FileSystemPath path1 = root1.WithInternalPath(current); - FileSystemPath path2 = root2.WithInternalPath(current); + FileSystemURL url1 = root1.WithPath(current); + FileSystemURL url2 = root2.WithPath(current); if (file_enum2->IsDirectory()) { FileSystemOperationContext context1(file_system_context()); FileSystemOperationContext context2(file_system_context()); - EXPECT_EQ(file_util1->IsDirectoryEmpty(&context1, path1), - file_util2->IsDirectoryEmpty(&context2, path2)); + EXPECT_EQ(file_util1->IsDirectoryEmpty(&context1, url1), + file_util2->IsDirectoryEmpty(&context2, url2)); continue; } EXPECT_TRUE(file_set1.find(current) != file_set1.end()); - VerifyFilesHaveSameContent(file_util1, file_util2, path1, path2); + VerifyFilesHaveSameContent(file_util1, file_util2, url1, url2); } } @@ -232,7 +232,7 @@ TEST_F(IsolatedFileUtilTest, BasicTest) { SCOPED_TRACE(testing::Message() << "Testing RegularTestCases " << i); const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; - FileSystemPath path = GetFileSystemPath(FilePath(test_case.path)); + FileSystemURL url = GetFileSystemURL(FilePath(test_case.path)); // See if we can query the file info via the isolated FileUtil. // (This should succeed since we have registered all the top-level @@ -241,7 +241,7 @@ TEST_F(IsolatedFileUtilTest, BasicTest) { FilePath platform_path; FileSystemOperationContext context(file_system_context()); ASSERT_EQ(base::PLATFORM_FILE_OK, - file_util()->GetFileInfo(&context, path, &info, &platform_path)); + file_util()->GetFileInfo(&context, url, &info, &platform_path)); // See if the obtained file info is correct. if (!test_case.is_directory) @@ -280,7 +280,7 @@ TEST_F(IsolatedFileUtilTest, UnregisteredPathsTest) { for (size_t i = 0; i < arraysize(kUnregisteredCases); ++i) { SCOPED_TRACE(testing::Message() << "Creating kUnregisteredCases " << i); const test::TestCaseRecord& test_case = kUnregisteredCases[i]; - FileSystemPath path = GetFileSystemPath(FilePath(test_case.path)); + FileSystemURL url = GetFileSystemURL(FilePath(test_case.path)); // This should fail as the paths in kUnregisteredCases are not included // in the dropped files (i.e. the regular test cases). @@ -288,7 +288,7 @@ TEST_F(IsolatedFileUtilTest, UnregisteredPathsTest) { FilePath platform_path; FileSystemOperationContext context(file_system_context()); ASSERT_EQ(base::PLATFORM_FILE_ERROR_SECURITY, - file_util()->GetFileInfo(&context, path, &info, &platform_path)); + file_util()->GetFileInfo(&context, url, &info, &platform_path)); } } @@ -323,12 +323,12 @@ TEST_F(IsolatedFileUtilTest, ReadDirectoryTest) { } // Perform ReadDirectory in the isolated filesystem. - FileSystemPath path = GetFileSystemPath(FilePath(test_case.path)); + FileSystemURL url = GetFileSystemURL(FilePath(test_case.path)); std::vector<base::FileUtilProxy::Entry> entries; FileSystemOperationContext context(file_system_context()); ASSERT_EQ(base::PLATFORM_FILE_OK, FileUtilHelper::ReadDirectory( - &context, file_util(), path, &entries)); + &context, file_util(), url, &entries)); EXPECT_EQ(expected_entry_map.size(), entries.size()); for (size_t i = 0; i < entries.size(); ++i) { @@ -347,13 +347,13 @@ TEST_F(IsolatedFileUtilTest, ReadDirectoryTest) { TEST_F(IsolatedFileUtilTest, GetLocalFilePathTest) { for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; - FileSystemPath path = GetFileSystemPath(FilePath(test_case.path)); + FileSystemURL url = GetFileSystemURL(FilePath(test_case.path)); FileSystemOperationContext context(file_system_context()); FilePath local_file_path; EXPECT_EQ(base::PLATFORM_FILE_OK, - file_util()->GetLocalFilePath(&context, path, &local_file_path)); + file_util()->GetLocalFilePath(&context, url, &local_file_path)); EXPECT_EQ(GetTestCasePlatformPath(test_case.path), local_file_path); } } @@ -361,10 +361,10 @@ TEST_F(IsolatedFileUtilTest, GetLocalFilePathTest) { TEST_F(IsolatedFileUtilTest, CopyOutFileTest) { scoped_ptr<FileSystemOperationContext> context( new FileSystemOperationContext(file_system_context())); - FileSystemPath root_path = GetFileSystemPath(FilePath()); + FileSystemURL root_url = GetFileSystemURL(FilePath()); scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( file_util()->CreateFileEnumerator(context.get(), - root_path, + root_url, true /* recursive */)); FilePath current; while (!(current = file_enum->Next()).empty()) { @@ -374,15 +374,15 @@ TEST_F(IsolatedFileUtilTest, CopyOutFileTest) { SCOPED_TRACE(testing::Message() << "Testing file copy " << current.value()); - FileSystemPath src_path = root_path.WithInternalPath(current); - FileSystemPath dest_path = GetOtherFileSystemPath(current); + FileSystemURL src_url = root_url.WithPath(current); + FileSystemURL dest_url = GetOtherFileSystemURL(current); // Create the parent directory of the destination. context.reset(new FileSystemOperationContext(file_system_context())); ASSERT_EQ(base::PLATFORM_FILE_OK, other_file_util()->CreateDirectory( context.get(), - GetOtherFileSystemPath(current.DirName()), + GetOtherFileSystemURL(current.DirName()), false /* exclusive */, true /* recursive */)); @@ -391,7 +391,7 @@ TEST_F(IsolatedFileUtilTest, CopyOutFileTest) { FileUtilHelper::Copy( context.get(), file_util(), other_file_util(), - src_path, dest_path)); + src_url, dest_url)); // The other way (copy-in) should not work. context.reset(new FileSystemOperationContext(file_system_context())); @@ -399,20 +399,20 @@ TEST_F(IsolatedFileUtilTest, CopyOutFileTest) { FileUtilHelper::Copy( context.get(), other_file_util(), file_util(), - dest_path, src_path)); + dest_url, src_url)); VerifyFilesHaveSameContent(file_util(), other_file_util(), - src_path, dest_path); + src_url, dest_url); } } TEST_F(IsolatedFileUtilTest, CopyOutDirectoryTest) { scoped_ptr<FileSystemOperationContext> context( new FileSystemOperationContext(file_system_context())); - FileSystemPath root_path = GetFileSystemPath(FilePath()); + FileSystemURL root_url = GetFileSystemURL(FilePath()); scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( file_util()->CreateFileEnumerator(context.get(), - root_path, + root_url, false /* recursive */)); FilePath current; while (!(current = file_enum->Next()).empty()) { @@ -422,15 +422,15 @@ TEST_F(IsolatedFileUtilTest, CopyOutDirectoryTest) { SCOPED_TRACE(testing::Message() << "Testing directory copy " << current.value()); - FileSystemPath src_path = root_path.WithInternalPath(current); - FileSystemPath dest_path = GetOtherFileSystemPath(current); + FileSystemURL src_url = root_url.WithPath(current); + FileSystemURL dest_url = GetOtherFileSystemURL(current); // Create the parent directory of the destination. context.reset(new FileSystemOperationContext(file_system_context())); ASSERT_EQ(base::PLATFORM_FILE_OK, other_file_util()->CreateDirectory( context.get(), - GetOtherFileSystemPath(current.DirName()), + GetOtherFileSystemURL(current.DirName()), false /* exclusive */, true /* recursive */)); @@ -439,19 +439,19 @@ TEST_F(IsolatedFileUtilTest, CopyOutDirectoryTest) { FileUtilHelper::Copy( context.get(), file_util(), other_file_util(), - src_path, dest_path)); + src_url, dest_url)); // The other way (copy-in) should not work for two reasons: // write is prohibited in the isolated filesystem, and copying directory // to non-empty directory shouldn't work. context.reset(new FileSystemOperationContext(file_system_context())); base::PlatformFileError result = FileUtilHelper::Copy( - context.get(), other_file_util(), file_util(), dest_path, src_path); + context.get(), other_file_util(), file_util(), dest_url, src_url); ASSERT_TRUE(result == base::PLATFORM_FILE_ERROR_FAILED || result == base::PLATFORM_FILE_ERROR_NOT_EMPTY); VerifyDirectoriesHaveSameContent(file_util(), other_file_util(), - src_path, dest_path); + src_url, dest_url); } } @@ -461,7 +461,7 @@ TEST_F(IsolatedFileUtilTest, TouchTest) { if (test_case.is_directory) continue; SCOPED_TRACE(testing::Message() << test_case.path); - FileSystemPath path = GetFileSystemPath(FilePath(test_case.path)); + FileSystemURL url = GetFileSystemURL(FilePath(test_case.path)); base::Time last_access_time = base::Time::FromTimeT(1000); base::Time last_modified_time = base::Time::FromTimeT(2000); @@ -469,14 +469,14 @@ TEST_F(IsolatedFileUtilTest, TouchTest) { // Set the filesystem non-writable and try calling Touch. ASSERT_TRUE(isolated_context()->SetWritable(filesystem_id(), false)); EXPECT_EQ(base::PLATFORM_FILE_ERROR_SECURITY, - file_util()->Touch(GetOperationContext().get(), path, + file_util()->Touch(GetOperationContext().get(), url, last_access_time, last_modified_time)); // Set the filesystem writable and try calling Touch. ASSERT_TRUE(isolated_context()->SetWritable(filesystem_id(), true)); EXPECT_EQ(base::PLATFORM_FILE_OK, - file_util()->Touch(GetOperationContext().get(), path, + file_util()->Touch(GetOperationContext().get(), url, last_access_time, last_modified_time)); @@ -484,7 +484,7 @@ TEST_F(IsolatedFileUtilTest, TouchTest) { base::PlatformFileInfo info; FilePath platform_path; ASSERT_EQ(base::PLATFORM_FILE_OK, - file_util()->GetFileInfo(GetOperationContext().get(), path, + file_util()->GetFileInfo(GetOperationContext().get(), url, &info, &platform_path)); EXPECT_EQ(last_access_time.ToTimeT(), info.last_accessed.ToTimeT()); EXPECT_EQ(last_modified_time.ToTimeT(), info.last_modified.ToTimeT()); @@ -498,12 +498,12 @@ TEST_F(IsolatedFileUtilTest, TruncateTest) { continue; SCOPED_TRACE(testing::Message() << test_case.path); - FileSystemPath path = GetFileSystemPath(FilePath(test_case.path)); + FileSystemURL url = GetFileSystemURL(FilePath(test_case.path)); // Set the filesystem non-writable and try calling Truncate. ASSERT_TRUE(isolated_context()->SetWritable(filesystem_id(), false)); EXPECT_EQ(base::PLATFORM_FILE_ERROR_SECURITY, - file_util()->Truncate(GetOperationContext().get(), path, 0)); + file_util()->Truncate(GetOperationContext().get(), url, 0)); base::PlatformFileInfo info; FilePath platform_path; @@ -513,17 +513,17 @@ TEST_F(IsolatedFileUtilTest, TruncateTest) { // Truncate to 0. EXPECT_EQ(base::PLATFORM_FILE_OK, - file_util()->Truncate(GetOperationContext().get(), path, 0)); + file_util()->Truncate(GetOperationContext().get(), url, 0)); ASSERT_EQ(base::PLATFORM_FILE_OK, - file_util()->GetFileInfo(GetOperationContext().get(), path, + file_util()->GetFileInfo(GetOperationContext().get(), url, &info, &platform_path)); EXPECT_EQ(0, info.size); // Truncate (extend) to 999. EXPECT_EQ(base::PLATFORM_FILE_OK, - file_util()->Truncate(GetOperationContext().get(), path, 999)); + file_util()->Truncate(GetOperationContext().get(), url, 999)); ASSERT_EQ(base::PLATFORM_FILE_OK, - file_util()->GetFileInfo(GetOperationContext().get(), path, + file_util()->GetFileInfo(GetOperationContext().get(), url, &info, &platform_path)); EXPECT_EQ(999, info.size); } |