| Index: webkit/fileapi/media/native_media_file_util_unittest.cc
|
| diff --git a/webkit/fileapi/media/native_media_file_util_unittest.cc b/webkit/fileapi/media/native_media_file_util_unittest.cc
|
| index 71afc1c3a9654ca092e681e13ae6591083a07d08..42cab0b69e5e0d23b0b21c9c5394d000d4e20382 100644
|
| --- a/webkit/fileapi/media/native_media_file_util_unittest.cc
|
| +++ b/webkit/fileapi/media/native_media_file_util_unittest.cc
|
| @@ -35,6 +35,8 @@ struct FilteringTestCase {
|
| const base::FilePath::CharType* path;
|
| bool is_directory;
|
| bool visible;
|
| + bool media_file;
|
| + const char* content;
|
| };
|
|
|
| const FilteringTestCase kFilteringTestCases[] = {
|
| @@ -45,10 +47,16 @@ const FilteringTestCase kFilteringTestCases[] = {
|
| { FPL("moga.cod"), true, true },
|
|
|
| // File should be visible if it's a supported media file.
|
| - { FPL("foo"), false, false }, // File without extension.
|
| - { FPL("bar.jpg"), false, true }, // Supported media file.
|
| - { FPL("baz.txt"), false, false }, // Non-media file.
|
| - { FPL("foobar.cod"), false, false }, // Unsupported media file.
|
| + // File without extension.
|
| + { FPL("foo"), false, false },
|
| + // Supported media file.
|
| + { FPL("bar.jpg"), false, true, true, "\xFF\xD8\xFF" },
|
| + // Unsupported masquerading file.
|
| + { FPL("sna.jpg"), false, true, false, "abc" },
|
| + // Non-media file.
|
| + { FPL("baz.txt"), false, false, false, "abc" },
|
| + // Unsupported media file.
|
| + { FPL("foobar.cod"), false, false, false, "abc" },
|
| };
|
|
|
| void ExpectEqHelper(const std::string& test_name,
|
| @@ -88,9 +96,21 @@ void PopulateDirectoryWithTestCases(const base::FilePath& dir,
|
| if (test_cases[i].is_directory) {
|
| ASSERT_TRUE(file_util::CreateDirectory(path));
|
| } else {
|
| + base::PlatformFile file_handle;
|
| bool created = false;
|
| ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| - NativeFileUtil::EnsureFileExists(path, &created));
|
| + NativeFileUtil::CreateOrOpen(
|
| + path,
|
| + base::PLATFORM_FILE_CREATE_ALWAYS |
|
| + base::PLATFORM_FILE_WRITE,
|
| + &file_handle, &created));
|
| + if (test_cases[i].content) {
|
| + int len = strlen(test_cases[i].content);
|
| + ASSERT_EQ(len,
|
| + base::WritePlatformFile(file_handle, 0, test_cases[i].content,
|
| + len));
|
| + }
|
| + base::ClosePlatformFile(file_handle);
|
| ASSERT_TRUE(created);
|
| }
|
| }
|
| @@ -226,7 +246,7 @@ TEST_F(NativeMediaFileUtilTest, ReadDirectoryFiltering) {
|
| url, base::Bind(&DidReadDirectory, &content, &completed));
|
| MessageLoop::current()->RunUntilIdle();
|
| EXPECT_TRUE(completed);
|
| - EXPECT_EQ(5u, content.size());
|
| + EXPECT_EQ(6u, content.size());
|
|
|
| for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) {
|
| base::FilePath::StringType name =
|
| @@ -598,4 +618,35 @@ TEST_F(NativeMediaFileUtilTest, TouchFileFiltering) {
|
| }
|
| }
|
|
|
| +void CreateSnapshotCallback(base::PlatformFileError* error,
|
| + base::PlatformFileError result, const base::PlatformFileInfo&,
|
| + const base::FilePath&,
|
| + const scoped_refptr<webkit_blob::ShareableFileReference>&) {
|
| + *error = result;
|
| +}
|
| +
|
| +TEST_F(NativeMediaFileUtilTest, CreateSnapshot) {
|
| + PopulateDirectoryWithTestCases(root_path(),
|
| + kFilteringTestCases,
|
| + arraysize(kFilteringTestCases));
|
| + for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) {
|
| + if (kFilteringTestCases[i].is_directory ||
|
| + !kFilteringTestCases[i].visible) {
|
| + continue;
|
| + }
|
| + FileSystemURL root_url = CreateURL(FPL(""));
|
| + FileSystemOperation* operation = NewOperation(root_url);
|
| + FileSystemURL url = CreateURL(kFilteringTestCases[i].path);
|
| + base::PlatformFileError expected_error, error;
|
| + if (kFilteringTestCases[i].media_file)
|
| + expected_error = base::PLATFORM_FILE_OK;
|
| + else
|
| + expected_error = base::PLATFORM_FILE_ERROR_SECURITY;
|
| + operation->CreateSnapshotFile(url,
|
| + base::Bind(CreateSnapshotCallback, &error));
|
| + MessageLoop::current()->RunUntilIdle();
|
| + ASSERT_EQ(expected_error, error);
|
| + }
|
| +}
|
| +
|
| } // namespace fileapi
|
|
|