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

Unified Diff: chrome/browser/media_galleries/fileapi/media_file_validator_browsertest.cc

Issue 20190002: Add a copy or move validator to that can handle support audio and video files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: to dcheck Created 7 years, 4 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 | « no previous file | chrome/browser/media_galleries/fileapi/media_file_validator_factory.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/media_galleries/fileapi/media_file_validator_browsertest.cc
diff --git a/chrome/browser/media_galleries/fileapi/media_file_validator_unittest.cc b/chrome/browser/media_galleries/fileapi/media_file_validator_browsertest.cc
similarity index 79%
rename from chrome/browser/media_galleries/fileapi/media_file_validator_unittest.cc
rename to chrome/browser/media_galleries/fileapi/media_file_validator_browsertest.cc
index 5fde5e470667666c5452b29b3abdc16bdba854f5..91901bfec56649d14e12669614e8c5103adb066b 100644
--- a/chrome/browser/media_galleries/fileapi/media_file_validator_unittest.cc
+++ b/chrome/browser/media_galleries/fileapi/media_file_validator_browsertest.cc
@@ -9,6 +9,7 @@
#include "base/files/scoped_temp_dir.h"
#include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_proxy.h"
+#include "base/path_service.h"
#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/test/browser_test.h"
@@ -32,7 +33,7 @@ const char kValidImage[] = "RIFF0\0\0\0WEBPVP8 $\0\0\0\xB2\x02\0\x9D\x01\x2A"
"\x01\0\x01\0\x2F\x9D\xCE\xE7s\xA8((((\x01\x9CK(\0"
"\x05\xCE\xB3l\0\0\xFE\xD8\x80\0\0";
-const char kInvalidImage[] = "Not an image";
+const char kInvalidMediaFile[] = "Not a media file";
const int64 kNoFileSize = -1;
@@ -55,6 +56,13 @@ void HandleCheckFileResult(int64 expected_size,
callback.Run(false);
}
+base::FilePath GetMediaTestDir() {
+ base::FilePath test_file;
+ if (!PathService::Get(base::DIR_SOURCE_ROOT, &test_file))
+ return base::FilePath();
+ return test_file.AppendASCII("media").AppendASCII("test").AppendASCII("data");
+}
+
} // namespace
namespace chrome {
@@ -78,6 +86,19 @@ class MediaFileValidatorTest : public InProcessBrowserTest {
loop_runner_->Run();
}
+ // Write |source| into |filename| in a test file system and try to move it
+ // into a media file system. The result is compared to |expected_result|.
+ void MoveTestFromFile(const std::string& filename,
+ const base::FilePath& source, bool expected_result) {
+ content::BrowserThread::PostTask(
+ content::BrowserThread::FILE,
+ FROM_HERE,
+ base::Bind(&MediaFileValidatorTest::SetupFromFileOnFileThread,
+ base::Unretained(this), filename, source, expected_result));
+ loop_runner_ = new content::MessageLoopRunner;
+ loop_runner_->Run();
+ }
+
private:
// Create the test files, filesystem objects, etc.
void SetupOnFileThread(const std::string& filename,
@@ -129,6 +150,14 @@ class MediaFileValidatorTest : public InProcessBrowserTest {
base::Unretained(this), expected_result)));
}
+ void SetupFromFileOnFileThread(const std::string& filename,
+ const base::FilePath& source,
+ bool expected_result) {
+ std::string content;
+ ASSERT_TRUE(file_util::ReadFileToString(source, &content));
+ SetupOnFileThread(filename, content, expected_result);
+ }
+
// Check that exactly one of |move_src_| and |move_dest_| exists.
// |src_expected| indicates which one should exist. When complete,
// |callback| is called with success/failure.
@@ -212,17 +241,43 @@ class MediaFileValidatorTest : public InProcessBrowserTest {
DISALLOW_COPY_AND_ASSIGN(MediaFileValidatorTest);
};
+IN_PROC_BROWSER_TEST_F(MediaFileValidatorTest, UnsupportedExtension) {
+ MoveTest("a.txt", std::string(kValidImage, arraysize(kValidImage)), false);
+}
+
IN_PROC_BROWSER_TEST_F(MediaFileValidatorTest, ValidImage) {
MoveTest("a.webp", std::string(kValidImage, arraysize(kValidImage)), true);
}
IN_PROC_BROWSER_TEST_F(MediaFileValidatorTest, InvalidImage) {
- MoveTest("a.webp", std::string(kInvalidImage, arraysize(kInvalidImage)),
- false);
+ MoveTest("a.webp", std::string(kInvalidMediaFile,
+ arraysize(kInvalidMediaFile)), false);
}
-IN_PROC_BROWSER_TEST_F(MediaFileValidatorTest, UnsupportedExtension) {
- MoveTest("a.txt", std::string(kValidImage, arraysize(kValidImage)), false);
+IN_PROC_BROWSER_TEST_F(MediaFileValidatorTest, InvalidAudio) {
+ MoveTest("a.ogg", std::string(kInvalidMediaFile,
+ arraysize(kInvalidMediaFile)), false);
+}
+
+IN_PROC_BROWSER_TEST_F(MediaFileValidatorTest, ValidAudio) {
+ base::FilePath test_file = GetMediaTestDir();
+ ASSERT_FALSE(test_file.empty());
+ test_file = test_file.AppendASCII("sfx.ogg");
+ MoveTestFromFile("sfx.ogg", test_file, true);
+}
+
+IN_PROC_BROWSER_TEST_F(MediaFileValidatorTest, InvalidVideo) {
+ base::FilePath test_file = GetMediaTestDir();
+ ASSERT_FALSE(test_file.empty());
+ test_file = test_file.AppendASCII("no_streams.webm");
+ MoveTestFromFile("no_streams.webm", test_file, false);
+}
+
+IN_PROC_BROWSER_TEST_F(MediaFileValidatorTest, ValidVideo) {
+ base::FilePath test_file = GetMediaTestDir();
+ ASSERT_FALSE(test_file.empty());
+ test_file = test_file.AppendASCII("bear-320x240-multitrack.webm");
+ MoveTestFromFile("multitrack.webm", test_file, true);
}
} // namespace chrome
« no previous file with comments | « no previous file | chrome/browser/media_galleries/fileapi/media_file_validator_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698