summaryrefslogtreecommitdiffstats
path: root/ppapi/tests
diff options
context:
space:
mode:
authornhiroki@chromium.org <nhiroki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-10 11:34:12 +0000
committernhiroki@chromium.org <nhiroki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-10 11:34:12 +0000
commit491af3c6d9727468104785d3df5b0583025f7420 (patch)
tree09e29b9e6d59220c7c22db94bbd869c9ddd62dd5 /ppapi/tests
parent021b50df6cc6fa48432c664cdb04219edde01cac (diff)
downloadchromium_src-491af3c6d9727468104785d3df5b0583025f7420.zip
chromium_src-491af3c6d9727468104785d3df5b0583025f7420.tar.gz
chromium_src-491af3c6d9727468104785d3df5b0583025f7420.tar.bz2
[Retry] PPAPI: Add new PPB_FileRef.MakeDirectory to support exclusive operation
Original Review: https://codereview.chromium.org/113363004/ Current PPB_FileRef.MakeDirectory returns PP_OK if a directory exists on the given path. This makes it difficult to create POSIX compatible API on top of PPAPI. This change introduces new PPB_FileRef.MakeDirectory as dev channel API. That makes a new directory according to the given PP_MakeDirectoryFlags values. The flags provide exclusive operation option. If exclusive flag is specified and a directory exists on the given path, the function fails and returns PP_ERROR_FILEEXISTS. BUG=314879 TEST=browser_tests TBR=dmichael@chromium.org,yzshen@chromium.org,tsepez@chromium.org Review URL: https://codereview.chromium.org/131403004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244148 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests')
-rw-r--r--ppapi/tests/test_file_io.cc3
-rw-r--r--ppapi/tests/test_file_ref.cc77
2 files changed, 53 insertions, 27 deletions
diff --git a/ppapi/tests/test_file_io.cc b/ppapi/tests/test_file_io.cc
index f699ba1..ec547f1 100644
--- a/ppapi/tests/test_file_io.cc
+++ b/ppapi/tests/test_file_io.cc
@@ -296,7 +296,8 @@ std::string TestFileIO::TestOpenDirectory() {
// Make a directory.
pp::FileRef dir_ref(file_system, "/test_dir_open_directory");
- callback.WaitForResult(dir_ref.MakeDirectory(callback.GetCallback()));
+ callback.WaitForResult(dir_ref.MakeDirectory(
+ PP_MAKEDIRECTORYFLAG_NONE, callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_OK, callback.result());
diff --git a/ppapi/tests/test_file_ref.cc b/ppapi/tests/test_file_ref.cc
index 0a10a32..015f54c 100644
--- a/ppapi/tests/test_file_ref.cc
+++ b/ppapi/tests/test_file_ref.cc
@@ -298,41 +298,59 @@ std::string TestFileRef::TestMakeDirectory() {
CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_OK, callback.result());
- // MakeDirectory.
- pp::FileRef dir_ref(file_system, "/test_dir_make_directory");
- callback.WaitForResult(dir_ref.MakeDirectory(callback.GetCallback()));
+ // Make a directory.
+ pp::FileRef dir_ref(file_system, "/dir_make_dir");
+ callback.WaitForResult(
+ dir_ref.MakeDirectory(PP_MAKEDIRECTORYFLAG_NONE, callback.GetCallback()));
+ CHECK_CALLBACK_BEHAVIOR(callback);
+ ASSERT_EQ(PP_OK, callback.result());
+
+ // Make a directory on the existing path without exclusive flag.
+ callback.WaitForResult(
+ dir_ref.MakeDirectory(PP_MAKEDIRECTORYFLAG_NONE, callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_OK, callback.result());
- // MakeDirectory aborted.
+ // Making a directory should be aborted.
int32_t rv = PP_ERROR_FAILED;
{
- rv = pp::FileRef(file_system, "/test_dir_make_abort")
- .MakeDirectory(callback.GetCallback());
+ rv = pp::FileRef(file_system, "/dir_make_dir_abort")
+ .MakeDirectory(PP_MAKEDIRECTORYFLAG_NONE, callback.GetCallback());
}
callback.WaitForAbortResult(rv);
CHECK_CALLBACK_BEHAVIOR(callback);
- // MakeDirectoryIncludingAncestors.
- dir_ref = pp::FileRef(file_system, "/dir_make_dir_1/dir_make_dir_2");
+ // Make nested directories.
+ dir_ref = pp::FileRef(file_system, "/dir_make_nested_dir_1/dir");
callback.WaitForResult(
- dir_ref.MakeDirectoryIncludingAncestors(callback.GetCallback()));
+ dir_ref.MakeDirectory(PP_MAKEDIRECTORYFLAG_WITH_ANCESTORS,
+ callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_OK, callback.result());
- // MakeDirectoryIncludingAncestors aborted.
- {
- rv = pp::FileRef(file_system, "/dir_make_abort_1/dir_make_abort_2")
- .MakeDirectoryIncludingAncestors(callback.GetCallback());
- }
- callback.WaitForAbortResult(rv);
+ dir_ref = pp::FileRef(file_system, "/dir_make_nested_dir_2/dir");
+ callback.WaitForResult(
+ dir_ref.MakeDirectory(PP_MAKEDIRECTORYFLAG_NONE, callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
+ ASSERT_EQ(PP_ERROR_FILENOTFOUND, callback.result());
+
+ // Ensure there is no directory on the path to test exclusive cases.
+ dir_ref = pp::FileRef(file_system, "/dir_make_dir_exclusive");
+ rv = DeleteDirectoryRecursively(&dir_ref);
+ ASSERT_TRUE(rv == PP_OK || rv == PP_ERROR_FILENOTFOUND);
+
+ // Make a directory exclusively.
+ callback.WaitForResult(
+ dir_ref.MakeDirectory(PP_MAKEDIRECTORYFLAG_EXCLUSIVE,
+ callback.GetCallback()));
+ CHECK_CALLBACK_BEHAVIOR(callback);
+ ASSERT_EQ(PP_OK, callback.result());
- // MakeDirectory with nested path should fail.
- dir_ref = pp::FileRef(file_system, "/dir_make_dir_3/dir_make_dir_4");
- callback.WaitForResult(dir_ref.MakeDirectory(callback.GetCallback()));
+ callback.WaitForResult(
+ dir_ref.MakeDirectory(PP_MAKEDIRECTORYFLAG_EXCLUSIVE,
+ callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
- ASSERT_NE(PP_OK, callback.result());
+ ASSERT_EQ(PP_ERROR_FILEEXISTS, callback.result());
PASS();
}
@@ -432,7 +450,8 @@ std::string TestFileRef::TestDeleteFileAndDirectory() {
ASSERT_EQ(PP_OK, callback.result());
pp::FileRef dir_ref(file_system, "/dir_delete");
- callback.WaitForResult(dir_ref.MakeDirectory(callback.GetCallback()));
+ callback.WaitForResult(dir_ref.MakeDirectory(
+ PP_MAKEDIRECTORYFLAG_NONE, callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_OK, callback.result());
@@ -442,7 +461,8 @@ std::string TestFileRef::TestDeleteFileAndDirectory() {
pp::FileRef nested_dir_ref(file_system, "/dir_delete_1/dir_delete_2");
callback.WaitForResult(
- nested_dir_ref.MakeDirectoryIncludingAncestors(callback.GetCallback()));
+ nested_dir_ref.MakeDirectory(PP_MAKEDIRECTORYFLAG_WITH_ANCESTORS,
+ callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_OK, callback.result());
@@ -496,7 +516,8 @@ std::string TestFileRef::TestRenameFileAndDirectory() {
ASSERT_EQ(PP_OK, callback.result());
pp::FileRef dir_ref(file_system, "/dir_rename");
- callback.WaitForResult(dir_ref.MakeDirectory(callback.GetCallback()));
+ callback.WaitForResult(dir_ref.MakeDirectory(
+ PP_MAKEDIRECTORYFLAG_NONE, callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_OK, callback.result());
@@ -508,7 +529,8 @@ std::string TestFileRef::TestRenameFileAndDirectory() {
pp::FileRef nested_dir_ref(file_system, "/dir_rename_1/dir_rename_2");
callback.WaitForResult(
- nested_dir_ref.MakeDirectoryIncludingAncestors(callback.GetCallback()));
+ nested_dir_ref.MakeDirectory(PP_MAKEDIRECTORYFLAG_WITH_ANCESTORS,
+ callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_OK, callback.result());
@@ -615,7 +637,8 @@ std::string TestFileRef::TestFileNameEscaping() {
std::string test_dir_path = "/dir_for_escaping_test";
// Create a directory in which to test.
pp::FileRef test_dir_ref(file_system, test_dir_path.c_str());
- callback.WaitForResult(test_dir_ref.MakeDirectory(callback.GetCallback()));
+ callback.WaitForResult(test_dir_ref.MakeDirectory(
+ PP_MAKEDIRECTORYFLAG_NONE, callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_OK, callback.result());
@@ -663,7 +686,8 @@ std::string TestFileRef::TestReadDirectoryEntries() {
int32_t rv = DeleteDirectoryRecursively(&test_dir);
ASSERT_TRUE(rv == PP_OK || rv == PP_ERROR_FILENOTFOUND);
- callback.WaitForResult(test_dir.MakeDirectory(callback.GetCallback()));
+ callback.WaitForResult(test_dir.MakeDirectory(
+ PP_MAKEDIRECTORYFLAG_NONE, callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_OK, callback.result());
@@ -690,7 +714,8 @@ std::string TestFileRef::TestReadDirectoryEntries() {
buffer << test_dir_name << '/' << dir_prefix << i;
pp::FileRef file_ref(file_system, buffer.str().c_str());
- callback.WaitForResult(file_ref.MakeDirectory(callback.GetCallback()));
+ callback.WaitForResult(file_ref.MakeDirectory(
+ PP_MAKEDIRECTORYFLAG_NONE, callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_OK, callback.result());