Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / media_galleries / fileapi / native_media_file_util_unittest.cc
index db6ad4f..d1a4828 100644 (file)
@@ -6,7 +6,7 @@
 #include <string>
 
 #include "base/bind.h"
-#include "base/file_util.h"
+#include "base/files/file_util.h"
 #include "base/files/scoped_temp_dir.h"
 #include "base/format_macros.h"
 #include "base/message_loop/message_loop.h"
 #include "base/time/time.h"
 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
 #include "chrome/browser/media_galleries/fileapi/native_media_file_util.h"
+#include "content/public/test/mock_special_storage_policy.h"
 #include "content/public/test/test_browser_thread.h"
 #include "content/public/test/test_file_system_options.h"
+#include "storage/browser/fileapi/external_mount_points.h"
+#include "storage/browser/fileapi/file_system_backend.h"
+#include "storage/browser/fileapi/file_system_context.h"
+#include "storage/browser/fileapi/file_system_operation_runner.h"
+#include "storage/browser/fileapi/file_system_url.h"
+#include "storage/browser/fileapi/isolated_context.h"
+#include "storage/browser/fileapi/native_file_util.h"
 #include "testing/gtest/include/gtest/gtest.h"
-#include "webkit/browser/fileapi/external_mount_points.h"
-#include "webkit/browser/fileapi/file_system_backend.h"
-#include "webkit/browser/fileapi/file_system_context.h"
-#include "webkit/browser/fileapi/file_system_operation_runner.h"
-#include "webkit/browser/fileapi/file_system_url.h"
-#include "webkit/browser/fileapi/isolated_context.h"
-#include "webkit/browser/fileapi/native_file_util.h"
-#include "webkit/browser/quota/mock_special_storage_policy.h"
 
 #define FPL(x) FILE_PATH_LITERAL(x)
 
-using fileapi::FileSystemOperation;
-using fileapi::FileSystemURL;
+using storage::FileSystemOperation;
+using storage::FileSystemURL;
 
 namespace {
 
@@ -65,24 +65,24 @@ const FilteringTestCase kFilteringTestCases[] = {
 };
 
 void ExpectEqHelper(const std::string& test_name,
-                    base::PlatformFileError expected,
-                    base::PlatformFileError actual) {
+                    base::File::Error expected,
+                    base::File::Error actual) {
   EXPECT_EQ(expected, actual) << test_name;
 }
 
 void ExpectMetadataEqHelper(const std::string& test_name,
-                            base::PlatformFileError expected,
+                            base::File::Error expected,
                             bool expected_is_directory,
-                            base::PlatformFileError actual,
-                            const base::PlatformFileInfo& file_info) {
+                            base::File::Error actual,
+                            const base::File::Info& file_info) {
   EXPECT_EQ(expected, actual) << test_name;
-  if (actual == base::PLATFORM_FILE_OK)
+  if (actual == base::File::FILE_OK)
     EXPECT_EQ(expected_is_directory, file_info.is_directory) << test_name;
 }
 
 void DidReadDirectory(std::set<base::FilePath::StringType>* content,
                       bool* completed,
-                      base::PlatformFileError error,
+                      base::File::Error error,
                       const FileEntryList& file_list,
                       bool has_more) {
   EXPECT_TRUE(!*completed);
@@ -98,11 +98,11 @@ void PopulateDirectoryWithTestCases(const base::FilePath& dir,
   for (size_t i = 0; i < n; ++i) {
     base::FilePath path = dir.Append(test_cases[i].path);
     if (test_cases[i].is_directory) {
-      ASSERT_TRUE(file_util::CreateDirectory(path));
+      ASSERT_TRUE(base::CreateDirectory(path));
     } else {
       ASSERT_TRUE(test_cases[i].content != NULL);
       int len = strlen(test_cases[i].content);
-      ASSERT_EQ(len, file_util::WriteFile(path, test_cases[i].content, len));
+      ASSERT_EQ(len, base::WriteFile(path, test_cases[i].content, len));
     }
   }
 }
@@ -115,52 +115,53 @@ class NativeMediaFileUtilTest : public testing::Test {
       : io_thread_(content::BrowserThread::IO, &message_loop_) {
   }
 
-  virtual void SetUp() {
+  void SetUp() override {
     ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
-    ASSERT_TRUE(file_util::CreateDirectory(root_path()));
+    ASSERT_TRUE(base::CreateDirectory(root_path()));
 
-    scoped_refptr<quota::SpecialStoragePolicy> storage_policy =
-        new quota::MockSpecialStoragePolicy();
+    scoped_refptr<storage::SpecialStoragePolicy> storage_policy =
+        new content::MockSpecialStoragePolicy();
 
-    ScopedVector<fileapi::FileSystemBackend> additional_providers;
+    ScopedVector<storage::FileSystemBackend> additional_providers;
     additional_providers.push_back(new MediaFileSystemBackend(
         data_dir_.path(), base::MessageLoopProxy::current().get()));
 
-    file_system_context_ = new fileapi::FileSystemContext(
+    file_system_context_ = new storage::FileSystemContext(
         base::MessageLoopProxy::current().get(),
         base::MessageLoopProxy::current().get(),
-        fileapi::ExternalMountPoints::CreateRefCounted().get(),
+        storage::ExternalMountPoints::CreateRefCounted().get(),
         storage_policy.get(),
         NULL,
         additional_providers.Pass(),
+        std::vector<storage::URLRequestAutoMountHandler>(),
         data_dir_.path(),
-        fileapi::CreateAllowFileAccessOptions());
+        content::CreateAllowFileAccessOptions());
 
     filesystem_id_ = isolated_context()->RegisterFileSystemForPath(
-        fileapi::kFileSystemTypeNativeMedia, root_path(), NULL);
+        storage::kFileSystemTypeNativeMedia, std::string(), root_path(), NULL);
 
     isolated_context()->AddReference(filesystem_id_);
   }
 
-  virtual void TearDown() {
+  void TearDown() override {
     isolated_context()->RemoveReference(filesystem_id_);
     file_system_context_ = NULL;
   }
 
  protected:
-  fileapi::FileSystemContext* file_system_context() {
+  storage::FileSystemContext* file_system_context() {
     return file_system_context_.get();
   }
 
   FileSystemURL CreateURL(const base::FilePath::CharType* test_case_path) {
     return file_system_context_->CreateCrackedFileSystemURL(
         origin(),
-        fileapi::kFileSystemTypeIsolated,
+        storage::kFileSystemTypeIsolated,
         GetVirtualPath(test_case_path));
   }
 
-  fileapi::IsolatedContext* isolated_context() {
-    return fileapi::IsolatedContext::GetInstance();
+  storage::IsolatedContext* isolated_context() {
+    return storage::IsolatedContext::GetInstance();
   }
 
   base::FilePath root_path() {
@@ -178,11 +179,9 @@ class NativeMediaFileUtilTest : public testing::Test {
     return GURL("http://example.com");
   }
 
-  fileapi::FileSystemType type() {
-    return fileapi::kFileSystemTypeNativeMedia;
-  }
+  storage::FileSystemType type() { return storage::kFileSystemTypeNativeMedia; }
 
-  fileapi::FileSystemOperationRunner* operation_runner() {
+  storage::FileSystemOperationRunner* operation_runner() {
     return file_system_context_->operation_runner();
   }
 
@@ -191,7 +190,7 @@ class NativeMediaFileUtilTest : public testing::Test {
   content::TestBrowserThread io_thread_;
 
   base::ScopedTempDir data_dir_;
-  scoped_refptr<fileapi::FileSystemContext> file_system_context_;
+  scoped_refptr<storage::FileSystemContext> file_system_context_;
 
   std::string filesystem_id_;
 
@@ -206,10 +205,10 @@ TEST_F(NativeMediaFileUtilTest, DirectoryExistsAndFileExistsFiltering) {
   for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) {
     FileSystemURL url = CreateURL(kFilteringTestCases[i].path);
 
-    base::PlatformFileError expectation =
+    base::File::Error expectation =
         kFilteringTestCases[i].visible ?
-        base::PLATFORM_FILE_OK :
-        base::PLATFORM_FILE_ERROR_NOT_FOUND;
+        base::File::FILE_OK :
+        base::File::FILE_ERROR_NOT_FOUND;
 
     std::string test_name =
         base::StringPrintf("DirectoryExistsAndFileExistsFiltering %" PRIuS, i);
@@ -259,10 +258,10 @@ TEST_F(NativeMediaFileUtilTest, CreateDirectoryFiltering) {
         std::string test_name = base::StringPrintf(
             "CreateFileAndCreateDirectoryFiltering run %d, test %" PRIuS,
             loop_count, i);
-        base::PlatformFileError expectation =
+        base::File::Error expectation =
             kFilteringTestCases[i].visible ?
-            base::PLATFORM_FILE_OK :
-            base::PLATFORM_FILE_ERROR_SECURITY;
+            base::File::FILE_OK :
+            base::File::FILE_ERROR_SECURITY;
         operation_runner()->CreateDirectory(
             url, false, false,
             base::Bind(&ExpectEqHelper, test_name, expectation));
@@ -287,25 +286,26 @@ TEST_F(NativeMediaFileUtilTest, CopySourceFiltering) {
       // Always start with an empty destination directory.
       // Copying to a non-empty destination directory is an invalid operation.
       ASSERT_TRUE(base::DeleteFile(dest_path, true));
-      ASSERT_TRUE(file_util::CreateDirectory(dest_path));
+      ASSERT_TRUE(base::CreateDirectory(dest_path));
 
       FileSystemURL root_url = CreateURL(FPL(""));
       FileSystemURL url = CreateURL(kFilteringTestCases[i].path);
 
       std::string test_name = base::StringPrintf(
           "CopySourceFiltering run %d test %" PRIuS, loop_count, i);
-      base::PlatformFileError expectation = base::PLATFORM_FILE_OK;
+      base::File::Error expectation = base::File::FILE_OK;
       if (loop_count == 0 || !kFilteringTestCases[i].visible) {
         // If the source does not exist or is not visible.
-        expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND;
+        expectation = base::File::FILE_ERROR_NOT_FOUND;
       } else if (!kFilteringTestCases[i].is_directory) {
         // Cannot copy a visible file to a directory.
-        expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
+        expectation = base::File::FILE_ERROR_INVALID_OPERATION;
       }
       operation_runner()->Copy(
-          url, dest_url,
-          fileapi::FileSystemOperation::OPTION_NONE,
-          fileapi::FileSystemOperationRunner::CopyProgressCallback(),
+          url,
+          dest_url,
+          storage::FileSystemOperation::OPTION_NONE,
+          storage::FileSystemOperationRunner::CopyProgressCallback(),
           base::Bind(&ExpectEqHelper, test_name, expectation));
       base::MessageLoop::current()->RunUntilIdle();
     }
@@ -320,7 +320,7 @@ TEST_F(NativeMediaFileUtilTest, CopyDestFiltering) {
       // Reset the test directory between the two loops to remove old
       // directories and create new ones that should pre-exist.
       ASSERT_TRUE(base::DeleteFile(root_path(), true));
-      ASSERT_TRUE(file_util::CreateDirectory(root_path()));
+      ASSERT_TRUE(base::CreateDirectory(root_path()));
       PopulateDirectoryWithTestCases(root_path(),
                                      kFilteringTestCases,
                                      arraysize(kFilteringTestCases));
@@ -330,7 +330,7 @@ TEST_F(NativeMediaFileUtilTest, CopyDestFiltering) {
     base::FilePath src_path = root_path().AppendASCII("foo.jpg");
     FileSystemURL src_url = CreateURL(FPL("foo.jpg"));
     static const char kDummyData[] = "dummy";
-    ASSERT_TRUE(file_util::WriteFile(src_path, kDummyData, strlen(kDummyData)));
+    ASSERT_TRUE(base::WriteFile(src_path, kDummyData, strlen(kDummyData)));
 
     for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) {
       if (loop_count == 0 && kFilteringTestCases[i].is_directory) {
@@ -343,7 +343,7 @@ TEST_F(NativeMediaFileUtilTest, CopyDestFiltering) {
 
       std::string test_name = base::StringPrintf(
           "CopyDestFiltering run %d test %" PRIuS, loop_count, i);
-      base::PlatformFileError expectation;
+      base::File::Error expectation;
       if (loop_count == 0) {
         // The destination path is a file here. The directory case has been
         // handled above.
@@ -351,26 +351,27 @@ TEST_F(NativeMediaFileUtilTest, CopyDestFiltering) {
         // creating it would be a security violation.
         expectation =
             kFilteringTestCases[i].visible ?
-            base::PLATFORM_FILE_OK :
-            base::PLATFORM_FILE_ERROR_SECURITY;
+            base::File::FILE_OK :
+            base::File::FILE_ERROR_SECURITY;
       } else {
         if (!kFilteringTestCases[i].visible) {
           // If the destination path exist and is not visible, then to the copy
           // operation, it looks like the file needs to be created, which is a
           // security violation.
-          expectation = base::PLATFORM_FILE_ERROR_SECURITY;
+          expectation = base::File::FILE_ERROR_SECURITY;
         } else if (kFilteringTestCases[i].is_directory) {
           // Cannot copy a file to a directory.
-          expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
+          expectation = base::File::FILE_ERROR_INVALID_OPERATION;
         } else {
           // Copying from a file to a visible file that exists is ok.
-          expectation = base::PLATFORM_FILE_OK;
+          expectation = base::File::FILE_OK;
         }
       }
       operation_runner()->Copy(
-          src_url, url,
-          fileapi::FileSystemOperation::OPTION_NONE,
-          fileapi::FileSystemOperationRunner::CopyProgressCallback(),
+          src_url,
+          url,
+          storage::FileSystemOperation::OPTION_NONE,
+          storage::FileSystemOperationRunner::CopyProgressCallback(),
           base::Bind(&ExpectEqHelper, test_name, expectation));
       base::MessageLoop::current()->RunUntilIdle();
     }
@@ -392,23 +393,25 @@ TEST_F(NativeMediaFileUtilTest, MoveSourceFiltering) {
       // Always start with an empty destination directory.
       // Moving to a non-empty destination directory is an invalid operation.
       ASSERT_TRUE(base::DeleteFile(dest_path, true));
-      ASSERT_TRUE(file_util::CreateDirectory(dest_path));
+      ASSERT_TRUE(base::CreateDirectory(dest_path));
 
       FileSystemURL root_url = CreateURL(FPL(""));
       FileSystemURL url = CreateURL(kFilteringTestCases[i].path);
 
       std::string test_name = base::StringPrintf(
           "MoveSourceFiltering run %d test %" PRIuS, loop_count, i);
-      base::PlatformFileError expectation = base::PLATFORM_FILE_OK;
+      base::File::Error expectation = base::File::FILE_OK;
       if (loop_count == 0 || !kFilteringTestCases[i].visible) {
         // If the source does not exist or is not visible.
-        expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND;
+        expectation = base::File::FILE_ERROR_NOT_FOUND;
       } else if (!kFilteringTestCases[i].is_directory) {
         // Cannot move a visible file to a directory.
-        expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
+        expectation = base::File::FILE_ERROR_INVALID_OPERATION;
       }
       operation_runner()->Move(
-          url, dest_url, fileapi::FileSystemOperation::OPTION_NONE,
+          url,
+          dest_url,
+          storage::FileSystemOperation::OPTION_NONE,
           base::Bind(&ExpectEqHelper, test_name, expectation));
       base::MessageLoop::current()->RunUntilIdle();
     }
@@ -423,7 +426,7 @@ TEST_F(NativeMediaFileUtilTest, MoveDestFiltering) {
       // Reset the test directory between the two loops to remove old
       // directories and create new ones that should pre-exist.
       ASSERT_TRUE(base::DeleteFile(root_path(), true));
-      ASSERT_TRUE(file_util::CreateDirectory(root_path()));
+      ASSERT_TRUE(base::CreateDirectory(root_path()));
       PopulateDirectoryWithTestCases(root_path(),
                                      kFilteringTestCases,
                                      arraysize(kFilteringTestCases));
@@ -441,14 +444,14 @@ TEST_F(NativeMediaFileUtilTest, MoveDestFiltering) {
       FileSystemURL src_url = CreateURL(FPL("foo.jpg"));
       static const char kDummyData[] = "dummy";
       ASSERT_TRUE(
-          file_util::WriteFile(src_path, kDummyData, strlen(kDummyData)));
+          base::WriteFile(src_path, kDummyData, strlen(kDummyData)));
 
       FileSystemURL root_url = CreateURL(FPL(""));
       FileSystemURL url = CreateURL(kFilteringTestCases[i].path);
 
       std::string test_name = base::StringPrintf(
           "MoveDestFiltering run %d test %" PRIuS, loop_count, i);
-      base::PlatformFileError expectation;
+      base::File::Error expectation;
       if (loop_count == 0) {
         // The destination path is a file here. The directory case has been
         // handled above.
@@ -456,24 +459,26 @@ TEST_F(NativeMediaFileUtilTest, MoveDestFiltering) {
         // creating it would be a security violation.
         expectation =
             kFilteringTestCases[i].visible ?
-            base::PLATFORM_FILE_OK :
-            base::PLATFORM_FILE_ERROR_SECURITY;
+            base::File::FILE_OK :
+            base::File::FILE_ERROR_SECURITY;
       } else {
         if (!kFilteringTestCases[i].visible) {
           // If the destination path exist and is not visible, then to the move
           // operation, it looks like the file needs to be created, which is a
           // security violation.
-          expectation = base::PLATFORM_FILE_ERROR_SECURITY;
+          expectation = base::File::FILE_ERROR_SECURITY;
         } else if (kFilteringTestCases[i].is_directory) {
           // Cannot move a file to a directory.
-          expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
+          expectation = base::File::FILE_ERROR_INVALID_OPERATION;
         } else {
           // Moving from a file to a visible file that exists is ok.
-          expectation = base::PLATFORM_FILE_OK;
+          expectation = base::File::FILE_OK;
         }
       }
       operation_runner()->Move(
-          src_url, url, fileapi::FileSystemOperation::OPTION_NONE,
+          src_url,
+          url,
+          storage::FileSystemOperation::OPTION_NONE,
           base::Bind(&ExpectEqHelper, test_name, expectation));
       base::MessageLoop::current()->RunUntilIdle();
     }
@@ -494,10 +499,10 @@ TEST_F(NativeMediaFileUtilTest, GetMetadataFiltering) {
 
       std::string test_name = base::StringPrintf(
           "GetMetadataFiltering run %d test %" PRIuS, loop_count, i);
-      base::PlatformFileError expectation = base::PLATFORM_FILE_OK;
+      base::File::Error expectation = base::File::FILE_OK;
       if (loop_count == 0 || !kFilteringTestCases[i].visible) {
         // Cannot get metadata from files that do not exist or are not visible.
-        expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND;
+        expectation = base::File::FILE_ERROR_NOT_FOUND;
       }
       operation_runner()->GetMetadata(
           url,
@@ -510,10 +515,40 @@ TEST_F(NativeMediaFileUtilTest, GetMetadataFiltering) {
   }
 }
 
-void CreateSnapshotCallback(base::PlatformFileError* error,
-    base::PlatformFileError result, const base::PlatformFileInfo&,
+TEST_F(NativeMediaFileUtilTest, RemoveFileFiltering) {
+  // Run the loop twice. The first run has no files. The second run does.
+  for (int loop_count = 0; loop_count < 2; ++loop_count) {
+    if (loop_count == 1) {
+      PopulateDirectoryWithTestCases(root_path(),
+                                     kFilteringTestCases,
+                                     arraysize(kFilteringTestCases));
+    }
+    for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) {
+      FileSystemURL root_url = CreateURL(FPL(""));
+      FileSystemURL url = CreateURL(kFilteringTestCases[i].path);
+
+      std::string test_name = base::StringPrintf(
+          "RemoveFiltering run %d test %" PRIuS, loop_count, i);
+      base::File::Error expectation = base::File::FILE_OK;
+      if (loop_count == 0 || !kFilteringTestCases[i].visible) {
+        // Cannot remove files that do not exist or are not visible.
+        expectation = base::File::FILE_ERROR_NOT_FOUND;
+      } else if (kFilteringTestCases[i].is_directory) {
+        expectation = base::File::FILE_ERROR_NOT_A_FILE;
+      }
+      operation_runner()->RemoveFile(
+          url, base::Bind(&ExpectEqHelper, test_name, expectation));
+      base::MessageLoop::current()->RunUntilIdle();
+    }
+  }
+}
+
+void CreateSnapshotCallback(
+    base::File::Error* error,
+    base::File::Error result,
+    const base::File::Info&,
     const base::FilePath&,
-    const scoped_refptr<webkit_blob::ShareableFileReference>&) {
+    const scoped_refptr<storage::ShareableFileReference>&) {
   *error = result;
 }
 
@@ -528,12 +563,12 @@ TEST_F(NativeMediaFileUtilTest, CreateSnapshot) {
     }
     FileSystemURL root_url = CreateURL(FPL(""));
     FileSystemURL url = CreateURL(kFilteringTestCases[i].path);
-    base::PlatformFileError expected_error, error;
+    base::File::Error expected_error, error;
     if (kFilteringTestCases[i].media_file)
-      expected_error = base::PLATFORM_FILE_OK;
+      expected_error = base::File::FILE_OK;
     else
-      expected_error = base::PLATFORM_FILE_ERROR_SECURITY;
-    error = base::PLATFORM_FILE_ERROR_FAILED;
+      expected_error = base::File::FILE_ERROR_SECURITY;
+    error = base::File::FILE_ERROR_FAILED;
     operation_runner()->CreateSnapshotFile(url,
         base::Bind(CreateSnapshotCallback, &error));
     base::MessageLoop::current()->RunUntilIdle();