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

Unified Diff: webkit/fileapi/file_system_operation_unittest.cc

Issue 6767010: More filesystem cleanup: convert URL-encoded-as-FilePath to actual URL, where (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: webkit/fileapi/file_system_operation_unittest.cc
===================================================================
--- webkit/fileapi/file_system_operation_unittest.cc (revision 79631)
+++ webkit/fileapi/file_system_operation_unittest.cc (working copy)
@@ -56,6 +56,16 @@
// Common temp base for nondestructive uses.
ScopedTempDir base_;
+ GURL URLForRelativePath(const std::string& path) const {
+ // Only the path will actually get used.
+ return GURL("file://").Resolve(base_.path().value()).Resolve(path);
+ }
+
+ GURL URLForPath(const FilePath& path) const {
+ // Only the path will actually get used.
+ return GURL("file://").Resolve(path.value());
+ }
+
// For post-operation status.
int status_;
base::PlatformFileInfo info_;
@@ -91,7 +101,7 @@
test_->set_entries(entries);
}
- virtual void DidOpenFileSystem(const std::string&, const FilePath&) {
+ virtual void DidOpenFileSystem(const std::string&, const GURL&) {
NOTREACHED();
}
@@ -113,12 +123,15 @@
kFileSystemTypeTemporary);
operation->file_system_operation_context()->set_dest_type(
kFileSystemTypeTemporary);
+ GURL origin_url("fake://fake.foo/");
+ operation->file_system_operation_context()->set_src_origin_url(origin_url);
+ operation->file_system_operation_context()->set_dest_origin_url(origin_url);
return operation;
}
TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) {
- FilePath src(base_.path().Append(FILE_PATH_LITERAL("a")));
- FilePath dest(base_.path().Append(FILE_PATH_LITERAL("b")));
+ GURL src(URLForRelativePath("a"));
+ GURL dest(URLForRelativePath("b"));
operation()->Move(src, dest);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
@@ -131,7 +144,7 @@
ASSERT_TRUE(file_util::CreateTemporaryDirInDir(src_dir.path(),
FILE_PATH_LITERAL("child_dir"),
&dest_dir_path));
- operation()->Move(src_dir.path(), dest_dir_path);
+ operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
}
@@ -146,7 +159,7 @@
FilePath dest_file;
file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file);
- operation()->Move(src_dir.path(), dest_file);
+ operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_file));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status());
}
@@ -161,7 +174,7 @@
FilePath child_file;
file_util::CreateTemporaryFileInDir(dest_dir.path(), &child_file);
- operation()->Move(src_dir.path(), dest_dir.path());
+ operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status());
}
@@ -176,7 +189,7 @@
ScopedTempDir dest_dir;
ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
- operation()->Move(src_file, dest_dir.path());
+ operation()->Move(URLForPath(src_file), URLForPath(dest_dir.path()));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status());
}
@@ -189,7 +202,7 @@
FILE_PATH_LITERAL("NonexistingDir")).Append(
FILE_PATH_LITERAL("NonexistingFile"));
- operation()->Move(src_dir.path(), nonexisting_file);
+ operation()->Move(URLForPath(src_dir.path()), URLForPath(nonexisting_file));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
}
@@ -205,7 +218,7 @@
FilePath dest_file;
file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file);
- operation()->Move(src_file, dest_file);
+ operation()->Move(URLForPath(src_file), URLForPath(dest_file));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(FileExists(dest_file));
@@ -221,7 +234,7 @@
ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
FilePath dest_file(dest_dir.path().Append(FILE_PATH_LITERAL("NewFile")));
- operation()->Move(src_file, dest_file);
+ operation()->Move(URLForPath(src_file), URLForPath(dest_file));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(FileExists(dest_file));
@@ -234,7 +247,7 @@
ScopedTempDir dest_dir;
ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
- operation()->Move(src_dir.path(), dest_dir.path());
+ operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_FALSE(file_util::DirectoryExists(src_dir.path()));
@@ -253,7 +266,7 @@
ASSERT_TRUE(dir.CreateUniqueTempDir());
FilePath dest_dir_path(dir.path().Append(FILE_PATH_LITERAL("NewDirectory")));
- operation()->Move(src_dir.path(), dest_dir_path);
+ operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_FALSE(file_util::DirectoryExists(src_dir.path()));
@@ -269,16 +282,14 @@
ScopedTempDir dest_dir;
ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
- operation()->Move(src_dir.path(), dest_dir.path());
+ operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(FileExists(dest_dir.path().Append(child_file.BaseName())));
}
TEST_F(FileSystemOperationTest, TestCopyFailureSrcDoesntExist) {
- FilePath src(base_.path().Append(FILE_PATH_LITERAL("a")));
- FilePath dest(base_.path().Append(FILE_PATH_LITERAL("b")));
- operation()->Copy(src, dest);
+ operation()->Copy(URLForRelativePath("a"), URLForRelativePath("b"));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
}
@@ -290,7 +301,7 @@
ASSERT_TRUE(file_util::CreateTemporaryDirInDir(src_dir.path(),
FILE_PATH_LITERAL("child_dir"),
&dest_dir_path));
- operation()->Copy(src_dir.path(), dest_dir_path);
+ operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
}
@@ -305,7 +316,7 @@
FilePath dest_file;
file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file);
- operation()->Copy(src_dir.path(), dest_file);
+ operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_file));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status());
}
@@ -320,7 +331,7 @@
FilePath child_file;
file_util::CreateTemporaryFileInDir(dest_dir.path(), &child_file);
- operation()->Copy(src_dir.path(), dest_dir.path());
+ operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status());
}
@@ -335,7 +346,7 @@
ScopedTempDir dest_dir;
ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
- operation()->Copy(src_file, dest_dir.path());
+ operation()->Copy(URLForPath(src_file), URLForPath(dest_dir.path()));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status());
}
@@ -351,7 +362,7 @@
FilePath nonexisting_file = nonexisting.Append(
FILE_PATH_LITERAL("DontExistFile"));
- operation()->Copy(src_dir, nonexisting_file);
+ operation()->Copy(URLForPath(src_dir), URLForPath(nonexisting_file));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
}
@@ -367,7 +378,7 @@
FilePath dest_file;
file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file);
- operation()->Copy(src_file, dest_file);
+ operation()->Copy(URLForPath(src_file), URLForPath(dest_file));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(FileExists(dest_file));
@@ -383,7 +394,7 @@
ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
FilePath dest_file(dest_dir.path().Append(FILE_PATH_LITERAL("NewFile")));
- operation()->Copy(src_file, dest_file);
+ operation()->Copy(URLForPath(src_file), URLForPath(dest_file));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(FileExists(dest_file));
@@ -396,7 +407,7 @@
ScopedTempDir dest_dir;
ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
- operation()->Copy(src_dir.path(), dest_dir.path());
+ operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
@@ -414,7 +425,7 @@
ASSERT_TRUE(dir.CreateUniqueTempDir());
FilePath dest_dir(dir.path().Append(FILE_PATH_LITERAL("NewDirectory")));
- operation()->Copy(src_dir.path(), dest_dir);
+ operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_dir));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(file_util::DirectoryExists(dest_dir));
@@ -429,7 +440,7 @@
ScopedTempDir dest_dir;
ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
- operation()->Copy(src_dir.path(), dest_dir.path());
+ operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(FileExists(dest_dir.path().Append(child_file.BaseName())));
@@ -442,7 +453,7 @@
FilePath file;
file_util::CreateTemporaryFileInDir(dir.path(), &file);
- operation()->CreateFile(file, true);
+ operation()->CreateFile(URLForPath(file), true);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status());
}
@@ -454,7 +465,7 @@
FilePath file;
file_util::CreateTemporaryFileInDir(dir.path(), &file);
- operation()->CreateFile(file, false);
+ operation()->CreateFile(URLForPath(file), false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(FileExists(file));
@@ -465,7 +476,7 @@
ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
FilePath file = dir.path().Append(FILE_PATH_LITERAL("FileDoesntExist"));
- operation()->CreateFile(file, true);
+ operation()->CreateFile(URLForPath(file), true);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(FileExists(file));
@@ -476,7 +487,7 @@
ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
FilePath file = dir.path().Append(FILE_PATH_LITERAL("FileDoesntExist"));
- operation()->CreateFile(file, false);
+ operation()->CreateFile(URLForPath(file), false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
}
@@ -488,7 +499,7 @@
FILE_PATH_LITERAL("DirDoesntExist")));
FilePath nonexisting_file = nonexisting.Append(
FILE_PATH_LITERAL("FileDoesntExist"));
- operation()->CreateDirectory(nonexisting_file, false, false);
+ operation()->CreateDirectory(URLForPath(nonexisting_file), false, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
}
@@ -497,7 +508,7 @@
// Exclusive and dir existing at path.
ScopedTempDir src_dir;
ASSERT_TRUE(src_dir.CreateUniqueTempDir());
- operation()->CreateDirectory(src_dir.path(), true, false);
+ operation()->CreateDirectory(URLForPath(src_dir.path()), true, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status());
}
@@ -508,7 +519,7 @@
ASSERT_TRUE(dir.CreateUniqueTempDir());
FilePath file;
file_util::CreateTemporaryFileInDir(dir.path(), &file);
- operation()->CreateDirectory(file, true, false);
+ operation()->CreateDirectory(URLForPath(file), true, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status());
}
@@ -517,14 +528,14 @@
// Dir exists and exclusive is false.
ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
- operation()->CreateDirectory(dir.path(), false, false);
+ operation()->CreateDirectory(URLForPath(dir.path()), false, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
// Dir doesn't exist.
FilePath nonexisting_dir_path(base_.path().Append(
FILE_PATH_LITERAL("nonexistingdir")));
- operation()->CreateDirectory(nonexisting_dir_path, false, false);
+ operation()->CreateDirectory(URLForPath(nonexisting_dir_path), false, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(file_util::DirectoryExists(nonexisting_dir_path));
@@ -535,7 +546,7 @@
FilePath nonexisting_dir_path(base_.path().Append(
FILE_PATH_LITERAL("nonexistingdir")));
- operation()->CreateDirectory(nonexisting_dir_path, true, false);
+ operation()->CreateDirectory(URLForPath(nonexisting_dir_path), true, false);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(file_util::DirectoryExists(nonexisting_dir_path));
@@ -544,16 +555,16 @@
TEST_F(FileSystemOperationTest, TestExistsAndMetadataFailure) {
FilePath nonexisting_dir_path(base_.path().Append(
FILE_PATH_LITERAL("nonexistingdir")));
- operation()->GetMetadata(nonexisting_dir_path);
+ operation()->GetMetadata(URLForPath(nonexisting_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
- operation()->FileExists(nonexisting_dir_path);
+ operation()->FileExists(URLForPath(nonexisting_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
file_util::EnsureEndsWithSeparator(&nonexisting_dir_path);
- operation()->DirectoryExists(nonexisting_dir_path);
+ operation()->DirectoryExists(URLForPath(nonexisting_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
}
@@ -562,11 +573,11 @@
ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
- operation()->DirectoryExists(dir.path());
+ operation()->DirectoryExists(URLForPath(dir.path()));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
- operation()->GetMetadata(dir.path());
+ operation()->GetMetadata(URLForPath(dir.path()));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_TRUE(info().is_directory);
@@ -574,11 +585,11 @@
FilePath file;
file_util::CreateTemporaryFileInDir(dir.path(), &file);
- operation()->FileExists(file);
+ operation()->FileExists(URLForPath(file));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
- operation()->GetMetadata(file);
+ operation()->GetMetadata(URLForPath(file));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_FALSE(info().is_directory);
@@ -588,13 +599,13 @@
TEST_F(FileSystemOperationTest, TestTypeMismatchErrors) {
ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
- operation()->FileExists(dir.path());
+ operation()->FileExists(URLForPath(dir.path()));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status());
FilePath file;
ASSERT_TRUE(file_util::CreateTemporaryFileInDir(dir.path(), &file));
- operation()->DirectoryExists(file);
+ operation()->DirectoryExists(URLForPath(file));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status());
}
@@ -604,7 +615,7 @@
FilePath nonexisting_dir_path(base_.path().Append(
FILE_PATH_LITERAL("NonExistingDir")));
file_util::EnsureEndsWithSeparator(&nonexisting_dir_path);
- operation()->ReadDirectory(nonexisting_dir_path);
+ operation()->ReadDirectory(URLForPath(nonexisting_dir_path));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
@@ -613,7 +624,7 @@
ASSERT_TRUE(dir.CreateUniqueTempDir());
FilePath file;
file_util::CreateTemporaryFileInDir(dir.path(), &file);
- operation()->ReadDirectory(file);
+ operation()->ReadDirectory(URLForPath(file));
MessageLoop::current()->RunAllPending();
// TODO(kkanetkar) crbug.com/54309 to change the error code.
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
@@ -632,7 +643,7 @@
ASSERT_TRUE(file_util::CreateTemporaryDirInDir(
parent_dir.path(), FILE_PATH_LITERAL("child_dir"), &child_dir));
- operation()->ReadDirectory(parent_dir.path());
+ operation()->ReadDirectory(URLForPath(parent_dir.path()));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationStatusNotSet, status());
EXPECT_EQ(2u, entries().size());
@@ -654,7 +665,7 @@
FILE_PATH_LITERAL("NonExistingDir")));
file_util::EnsureEndsWithSeparator(&nonexisting);
- operation()->Remove(nonexisting, false /* recursive */);
+ operation()->Remove(URLForPath(nonexisting), false /* recursive */);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
@@ -672,7 +683,7 @@
ASSERT_TRUE(file_util::CreateTemporaryDirInDir(
parent_dir.path(), FILE_PATH_LITERAL("child_dir"), &child_dir));
- operation()->Remove(parent_dir.path(), false /* recursive */);
+ operation()->Remove(URLForPath(parent_dir.path()), false /* recursive */);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY,
status());
@@ -683,7 +694,7 @@
ASSERT_TRUE(empty_dir.CreateUniqueTempDir());
EXPECT_TRUE(file_util::DirectoryExists(empty_dir.path()));
- operation()->Remove(empty_dir.path(), false /* recursive */);
+ operation()->Remove(URLForPath(empty_dir.path()), false /* recursive */);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_FALSE(file_util::DirectoryExists(empty_dir.path()));
@@ -701,7 +712,7 @@
ASSERT_TRUE(file_util::CreateTemporaryDirInDir(
parent_dir.path(), FILE_PATH_LITERAL("child_dir"), &child_dir));
- operation()->Remove(parent_dir.path(), true /* recursive */);
+ operation()->Remove(URLForPath(parent_dir.path()), true /* recursive */);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_FALSE(file_util::DirectoryExists(parent_dir.path()));
@@ -721,7 +732,7 @@
file_util::WriteFile(file, test_data, data_size));
// Check that its length is the size of the data written.
- operation()->GetMetadata(file);
+ operation()->GetMetadata(URLForPath(file));
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
EXPECT_FALSE(info().is_directory);
@@ -729,7 +740,7 @@
// Extend the file by truncating it.
int length = 17;
- operation()->Truncate(file, length);
+ operation()->Truncate(URLForPath(file), length);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());
@@ -750,7 +761,7 @@
// Shorten the file by truncating it.
length = 3;
- operation()->Truncate(file, length);
+ operation()->Truncate(URLForPath(file), length);
MessageLoop::current()->RunAllPending();
EXPECT_EQ(kFileOperationSucceeded, status());

Powered by Google App Engine
This is Rietveld 408576698