Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Unified Diff: webkit/fileapi/media/native_media_file_util_unittest.cc

Issue 12703012: Have media gallery (through native media file util) use MIME sniffer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Unit test working. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/fileapi/media/native_media_file_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « webkit/fileapi/media/native_media_file_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698