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..507282399d70db9c1d238425ca60fd7e241ec6cc 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[] = { |
@@ -46,9 +48,10 @@ const FilteringTestCase kFilteringTestCases[] = { |
// 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. |
+ { FPL("bar.jpg"), false, true, true, "\xFF\xD8\xFF" }, // Supported media file. |
+ { FPL("sna.jpg"), false, true, false, "abc" }, // Unsupported masquerading file. |
+ { FPL("baz.txt"), false, false, false, "abc" }, // Non-media file. |
+ { FPL("foobar.cod"), false, false, false, "abc" }, // Unsupported media file. |
}; |
void ExpectEqHelper(const std::string& test_name, |
@@ -88,9 +91,23 @@ 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( |
vandebo (ex-Chrome)
2013/04/03 18:54:14
It might be easier to use WriteFile() from base/fi
Kevin Bailey
2013/04/04 16:07:28
I agree, but that would remove a test ("created").
vandebo (ex-Chrome)
2013/04/04 20:24:20
I think it's ok to remove the assertion that we ju
Kevin Bailey
2013/04/05 15:24:35
Is this what you had in mind ?
|
+ 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); |
+ if (test_cases[i].content) { |
+ } |
ASSERT_TRUE(created); |
} |
} |
@@ -226,7 +243,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 +615,36 @@ 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 && |
vandebo (ex-Chrome)
2013/04/03 18:54:14
nit: reverse the case of the if and use continue.
Kevin Bailey
2013/04/04 16:07:28
Done.
Kevin Bailey
2013/04/04 16:07:28
Done.
|
+ kFilteringTestCases[i].visible) { |
+ FileSystemURL root_url = CreateURL(FPL("")); |
+ FileSystemOperation* operation = NewOperation(root_url); |
+ FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
+ if (kFilteringTestCases[i].media_file) { |
vandebo (ex-Chrome)
2013/04/03 18:54:14
nit: use an "expected" variable and assign it base
Kevin Bailey
2013/04/04 16:07:28
Done.
|
+ base::PlatformFileError error; |
+ operation->CreateSnapshotFile(url, |
vandebo (ex-Chrome)
2013/04/03 18:54:14
After op->CrateSnapshotFile, you should call Messa
Kevin Bailey
2013/04/04 16:07:28
Done.
|
+ base::Bind(CreateSnapshotCallback, &error)); |
+ ASSERT_EQ(base::PLATFORM_FILE_OK, error); |
+ } else { |
+ base::PlatformFileError error; |
+ operation->CreateSnapshotFile(url, |
+ base::Bind(CreateSnapshotCallback, &error)); |
+ ASSERT_EQ(base::PLATFORM_FILE_ERROR_SECURITY, error); |
+ } |
+ } |
+ } |
+} |
+ |
} // namespace fileapi |