Index: chrome/browser/media_galleries/fileapi/native_media_file_util_unittest.cc |
diff --git a/chrome/browser/media_galleries/fileapi/native_media_file_util_unittest.cc b/chrome/browser/media_galleries/fileapi/native_media_file_util_unittest.cc |
index 333495d4f7986b6d65c7949fe18317ce854433e1..954a8f374bf1949ace79685ad3d443327a68190d 100644 |
--- a/chrome/browser/media_galleries/fileapi/native_media_file_util_unittest.cc |
+++ b/chrome/browser/media_galleries/fileapi/native_media_file_util_unittest.cc |
@@ -12,6 +12,7 @@ |
#include "base/message_loop.h" |
#include "base/stringprintf.h" |
#include "base/time.h" |
+#include "chrome/browser/media_galleries/fileapi/async_file_util_test_helper.h" |
#include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.h" |
#include "chrome/browser/media_galleries/fileapi/native_media_file_util.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -138,8 +139,8 @@ class NativeMediaFileUtilTest : public testing::Test { |
data_dir_.path(), |
fileapi::CreateAllowFileAccessOptions()); |
- file_util_ = file_system_context_->GetFileUtil( |
- fileapi::kFileSystemTypeNativeMedia); |
+ file_util_.reset( |
+ new fileapi::AsyncFileUtilTestHelper(new NativeMediaFileUtil())); |
filesystem_id_ = isolated_context()->RegisterFileSystemForPath( |
fileapi::kFileSystemTypeNativeMedia, root_path(), NULL); |
@@ -180,7 +181,7 @@ class NativeMediaFileUtilTest : public testing::Test { |
} |
fileapi::FileSystemFileUtil* file_util() { |
- return file_util_; |
+ return file_util_.get(); |
} |
GURL origin() { |
@@ -201,7 +202,7 @@ class NativeMediaFileUtilTest : public testing::Test { |
base::ScopedTempDir data_dir_; |
scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
- fileapi::FileSystemFileUtil* file_util_; |
+ scoped_ptr<fileapi::FileSystemFileUtil> file_util_; |
std::string filesystem_id_; |
DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtilTest); |
@@ -257,248 +258,6 @@ TEST_F(NativeMediaFileUtilTest, ReadDirectoryFiltering) { |
} |
} |
-TEST_F(NativeMediaFileUtilTest, CreateFileAndCreateDirectoryFiltering) { |
- // Run the loop twice. The second loop attempts to create files that are |
- // pre-existing. Though the result should be the same. |
- for (int loop_count = 0; loop_count < 2; ++loop_count) { |
- for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
- FileSystemURL root_url = CreateURL(FPL("")); |
- FileSystemOperation* operation = NewOperation(root_url); |
- |
- FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
- |
- std::string test_name = base::StringPrintf( |
- "CreateFileAndCreateDirectoryFiltering run %d, test %" PRIuS, |
- loop_count, i); |
- base::PlatformFileError expectation = |
- kFilteringTestCases[i].visible ? |
- base::PLATFORM_FILE_OK : |
- base::PLATFORM_FILE_ERROR_SECURITY; |
- if (kFilteringTestCases[i].is_directory) { |
- operation->CreateDirectory( |
- url, false, false, |
- base::Bind(&ExpectEqHelper, test_name, expectation)); |
- } else { |
- operation->CreateFile( |
- url, false, base::Bind(&ExpectEqHelper, test_name, expectation)); |
- } |
- base::MessageLoop::current()->RunUntilIdle(); |
- } |
- } |
-} |
- |
-TEST_F(NativeMediaFileUtilTest, CopySourceFiltering) { |
- base::FilePath dest_path = root_path().AppendASCII("dest"); |
- FileSystemURL dest_url = CreateURL(FPL("dest")); |
- |
- // Run the loop twice. The first run has no source 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) { |
- // Always start with an empty destination directory. |
- // Copying to a non-empty destination directory is an invalid operation. |
- ASSERT_TRUE(file_util::Delete(dest_path, true)); |
- ASSERT_TRUE(file_util::CreateDirectory(dest_path)); |
- |
- FileSystemURL root_url = CreateURL(FPL("")); |
- FileSystemOperation* operation = NewOperation(root_url); |
- |
- 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; |
- if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
- // If the source does not exist or is not visible. |
- expectation = base::PLATFORM_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; |
- } |
- operation->Copy( |
- url, dest_url, base::Bind(&ExpectEqHelper, test_name, expectation)); |
- base::MessageLoop::current()->RunUntilIdle(); |
- } |
- } |
-} |
- |
-TEST_F(NativeMediaFileUtilTest, CopyDestFiltering) { |
- // Run the loop twice. The first run has no destination files. |
- // The second run does. |
- for (int loop_count = 0; loop_count < 2; ++loop_count) { |
- if (loop_count == 1) { |
- // Reset the test directory between the two loops to remove old |
- // directories and create new ones that should pre-exist. |
- ASSERT_TRUE(file_util::Delete(root_path(), true)); |
- ASSERT_TRUE(file_util::CreateDirectory(root_path())); |
- PopulateDirectoryWithTestCases(root_path(), |
- kFilteringTestCases, |
- arraysize(kFilteringTestCases)); |
- } |
- |
- // Always create a dummy source data file. |
- 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))); |
- |
- for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
- if (loop_count == 0 && kFilteringTestCases[i].is_directory) { |
- // These directories do not exist in this case, so Copy() will not |
- // treat them as directories. Thus invalidating these test cases. |
- // Continue now to avoid creating a new |operation| below that goes |
- // unused. |
- continue; |
- } |
- FileSystemURL root_url = CreateURL(FPL("")); |
- FileSystemOperation* operation = NewOperation(root_url); |
- |
- FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
- |
- std::string test_name = base::StringPrintf( |
- "CopyDestFiltering run %d test %" PRIuS, loop_count, i); |
- base::PlatformFileError expectation; |
- if (loop_count == 0) { |
- // The destination path is a file here. The directory case has been |
- // handled above. |
- // If the destination path does not exist and is not visible, then |
- // creating it would be a security violation. |
- expectation = |
- kFilteringTestCases[i].visible ? |
- base::PLATFORM_FILE_OK : |
- base::PLATFORM_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; |
- } else if (kFilteringTestCases[i].is_directory) { |
- // Cannot copy a file to a directory. |
- expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
- } else { |
- // Copying from a file to a visible file that exists is ok. |
- expectation = base::PLATFORM_FILE_OK; |
- } |
- } |
- operation->Copy( |
- src_url, url, base::Bind(&ExpectEqHelper, test_name, expectation)); |
- base::MessageLoop::current()->RunUntilIdle(); |
- } |
- } |
-} |
- |
-TEST_F(NativeMediaFileUtilTest, MoveSourceFiltering) { |
- base::FilePath dest_path = root_path().AppendASCII("dest"); |
- FileSystemURL dest_url = CreateURL(FPL("dest")); |
- |
- // Run the loop twice. The first run has no source 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) { |
- // Always start with an empty destination directory. |
- // Moving to a non-empty destination directory is an invalid operation. |
- ASSERT_TRUE(file_util::Delete(dest_path, true)); |
- ASSERT_TRUE(file_util::CreateDirectory(dest_path)); |
- |
- FileSystemURL root_url = CreateURL(FPL("")); |
- FileSystemOperation* operation = NewOperation(root_url); |
- |
- 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; |
- if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
- // If the source does not exist or is not visible. |
- expectation = base::PLATFORM_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; |
- } |
- operation->Move( |
- url, dest_url, base::Bind(&ExpectEqHelper, test_name, expectation)); |
- base::MessageLoop::current()->RunUntilIdle(); |
- } |
- } |
-} |
- |
-TEST_F(NativeMediaFileUtilTest, MoveDestFiltering) { |
- // Run the loop twice. The first run has no destination files. |
- // The second run does. |
- for (int loop_count = 0; loop_count < 2; ++loop_count) { |
- if (loop_count == 1) { |
- // Reset the test directory between the two loops to remove old |
- // directories and create new ones that should pre-exist. |
- ASSERT_TRUE(file_util::Delete(root_path(), true)); |
- ASSERT_TRUE(file_util::CreateDirectory(root_path())); |
- PopulateDirectoryWithTestCases(root_path(), |
- kFilteringTestCases, |
- arraysize(kFilteringTestCases)); |
- } |
- |
- for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
- if (loop_count == 0 && kFilteringTestCases[i].is_directory) { |
- // These directories do not exist in this case, so Copy() will not |
- // treat them as directories. Thus invalidating these test cases. |
- // Continue now to avoid creating a new |operation| below that goes |
- // unused. |
- continue; |
- } |
- |
- // Create the source file for every test case because it might get moved. |
- 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))); |
- |
- FileSystemURL root_url = CreateURL(FPL("")); |
- FileSystemOperation* operation = NewOperation(root_url); |
- |
- FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
- |
- std::string test_name = base::StringPrintf( |
- "MoveDestFiltering run %d test %" PRIuS, loop_count, i); |
- base::PlatformFileError expectation; |
- if (loop_count == 0) { |
- // The destination path is a file here. The directory case has been |
- // handled above. |
- // If the destination path does not exist and is not visible, then |
- // creating it would be a security violation. |
- expectation = |
- kFilteringTestCases[i].visible ? |
- base::PLATFORM_FILE_OK : |
- base::PLATFORM_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; |
- } else if (kFilteringTestCases[i].is_directory) { |
- // Cannot move a file to a directory. |
- expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
- } else { |
- // Moving from a file to a visible file that exists is ok. |
- expectation = base::PLATFORM_FILE_OK; |
- } |
- } |
- operation->Move( |
- src_url, url, base::Bind(&ExpectEqHelper, test_name, expectation)); |
- base::MessageLoop::current()->RunUntilIdle(); |
- } |
- } |
-} |
- |
TEST_F(NativeMediaFileUtilTest, GetMetadataFiltering) { |
// Run the loop twice. The first run has no files. The second run does. |
for (int loop_count = 0; loop_count < 2; ++loop_count) { |
@@ -530,95 +289,6 @@ TEST_F(NativeMediaFileUtilTest, GetMetadataFiltering) { |
} |
} |
-TEST_F(NativeMediaFileUtilTest, RemoveFiltering) { |
- // 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("")); |
- FileSystemOperation* operation = NewOperation(root_url); |
- |
- FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
- |
- std::string test_name = base::StringPrintf( |
- "RemoveFiltering run %d test %" PRIuS, loop_count, i); |
- base::PlatformFileError expectation = base::PLATFORM_FILE_OK; |
- if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
- // Cannot remove files that do not exist or are not visible. |
- expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
- } |
- operation->Remove( |
- url, false, base::Bind(&ExpectEqHelper, test_name, expectation)); |
- base::MessageLoop::current()->RunUntilIdle(); |
- } |
- } |
-} |
- |
-TEST_F(NativeMediaFileUtilTest, TruncateFiltering) { |
- // 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("")); |
- FileSystemOperation* operation = NewOperation(root_url); |
- |
- FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
- |
- std::string test_name = base::StringPrintf( |
- "TruncateFiltering run %d test %" PRIuS, loop_count, i); |
- base::PlatformFileError expectation = base::PLATFORM_FILE_OK; |
- if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
- // Cannot truncate files that do not exist or are not visible. |
- expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
- } else if (kFilteringTestCases[i].is_directory) { |
- // Cannot truncate directories. |
- expectation = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; |
- } |
- operation->Truncate( |
- url, 0, base::Bind(&ExpectEqHelper, test_name, expectation)); |
- base::MessageLoop::current()->RunUntilIdle(); |
- } |
- } |
-} |
- |
-TEST_F(NativeMediaFileUtilTest, TouchFileFiltering) { |
- base::Time time = base::Time::Now(); |
- |
- // 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("")); |
- FileSystemOperation* operation = NewOperation(root_url); |
- |
- FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
- |
- std::string test_name = base::StringPrintf( |
- "TouchFileFiltering run %d test %" PRIuS, loop_count, i); |
- base::PlatformFileError expectation = base::PLATFORM_FILE_OK; |
- if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
- // Files do not exists. Touch fails. |
- expectation = base::PLATFORM_FILE_ERROR_FAILED; |
- } |
- operation->TouchFile( |
- url, time, time, base::Bind(&ExpectEqHelper, test_name, expectation)); |
- base::MessageLoop::current()->RunUntilIdle(); |
- } |
- } |
-} |
- |
void CreateSnapshotCallback(base::PlatformFileError* error, |
base::PlatformFileError result, const base::PlatformFileInfo&, |
const base::FilePath&, |