PPAPI: modify FileIO.Open to return PP_ERROR_NOTAFILE when opening a directory
authornhiroki@chromium.org <nhiroki@chromium.org@4ff67af0-8c30-449e-8e8b-ad334ec8d88c>
Fri, 21 Dec 2012 07:52:15 +0000 (07:52 +0000)
committernhiroki@chromium.org <nhiroki@chromium.org@4ff67af0-8c30-449e-8e8b-ad334ec8d88c>
Fri, 21 Dec 2012 07:52:15 +0000 (07:52 +0000)
BUG=132201
TEST=browser_tests --gtest_filter=\*OpenDirectory\*

Review URL: https://chromiumcodereview.appspot.com/11587008

git-svn-id: http://src.chromium.org/svn/trunk/src/ppapi@174360 4ff67af0-8c30-449e-8e8b-ad334ec8d88c

api/pp_errors.idl
c/pp_errors.h
shared_impl/file_type_conversion.cc
tests/test_file_io.cc
tests/test_file_io.h

index fc0ff4a..54a3ace 100644 (file)
    * unexpectedly.
    */
   PP_ERROR_FILECHANGED    = -23,
+  /** This value indicates that the pathname does not reference a file. */
+  PP_ERROR_NOTAFILE       = -24,
   /** This value indicates failure due to a time limit being exceeded. */
   PP_ERROR_TIMEDOUT       = -30,
   /**
index b02ee1b..180ebb3 100644 (file)
@@ -3,7 +3,7 @@
  * found in the LICENSE file.
  */
 
-/* From pp_errors.idl modified Tue Mar 13 17:32:37 2012. */
+/* From pp_errors.idl modified Thu Dec 20 14:28:44 2012. */
 
 #ifndef PPAPI_C_PP_ERRORS_H_
 #define PPAPI_C_PP_ERRORS_H_
@@ -103,6 +103,8 @@ enum {
    * unexpectedly.
    */
   PP_ERROR_FILECHANGED = -23,
+  /** This value indicates that the pathname does not reference a file. */
+  PP_ERROR_NOTAFILE = -24,
   /** This value indicates failure due to a time limit being exceeded. */
   PP_ERROR_TIMEDOUT = -30,
   /**
index a9bd435..5185daa 100644 (file)
@@ -26,6 +26,8 @@ int PlatformFileErrorToPepperError(base::PlatformFileError error_code) {
       return PP_ERROR_NOSPACE;
     case base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY:
       return PP_ERROR_FAILED;
+    case base::PLATFORM_FILE_ERROR_NOT_A_FILE:
+      return PP_ERROR_NOTAFILE;
     default:
       return PP_ERROR_FAILED;
   }
index 9f88f00..e85bd55 100644 (file)
@@ -137,6 +137,7 @@ bool TestFileIO::Init() {
 
 void TestFileIO::RunTests(const std::string& filter) {
   RUN_TEST_FORCEASYNC_AND_NOT(Open, filter);
+  RUN_TEST_FORCEASYNC_AND_NOT(OpenDirectory, filter);
   RUN_TEST_FORCEASYNC_AND_NOT(ReadWriteSetLength, filter);
   RUN_TEST_FORCEASYNC_AND_NOT(ReadToArrayWriteSetLength, filter);
   RUN_TEST_FORCEASYNC_AND_NOT(TouchQuery, filter);
@@ -249,6 +250,43 @@ std::string TestFileIO::TestOpen() {
   PASS();
 }
 
+std::string TestFileIO::TestOpenDirectory() {
+  TestCompletionCallback callback(instance_->pp_instance(), force_async_);
+
+  pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
+  int32_t rv = file_system.Open(1024, callback);
+  if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
+    return ReportError("FileSystem::Open force_async", rv);
+  if (rv == PP_OK_COMPLETIONPENDING)
+    rv = callback.WaitForResult();
+  if (rv != PP_OK)
+    return ReportError("FileSystem::Open", rv);
+
+  // Make a directory.
+  pp::FileRef dir_ref(file_system, "/test_dir_open_directory");
+  rv = dir_ref.MakeDirectory(callback);
+  if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
+    return ReportError("FileSystem::MakeDirectory force_async", rv);
+  if (rv == PP_OK_COMPLETIONPENDING)
+    rv = callback.WaitForResult();
+  if (rv != PP_OK)
+    return ReportError("FileSystem::MakeDirectory", rv);
+
+  // Open the directory. This is expected to fail since directories cannot be
+  // opened.
+  pp::FileIO file_io(instance_);
+  rv = file_io.Open(dir_ref, PP_FILEOPENFLAG_READ, callback);
+  if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
+    return ReportError("FileIO::Open force_async", rv);
+  if (rv == PP_OK_COMPLETIONPENDING)
+    rv = callback.WaitForResult();
+  // Check for failing open operation for the directory.
+  if (rv != PP_ERROR_NOTAFILE)
+    return ReportError("FileIO::Open", rv);
+
+  PASS();
+}
+
 std::string TestFileIO::TestReadWriteSetLength() {
   TestCompletionCallback callback(instance_->pp_instance(), force_async_);
 
index bf1c798..8db0ba1 100644 (file)
@@ -38,6 +38,7 @@ class TestFileIO : public TestCase {
   };
 
   std::string TestOpen();
+  std::string TestOpenDirectory();
   std::string TestReadWriteSetLength();
   std::string TestReadToArrayWriteSetLength();
   std::string TestTouchQuery();