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

Unified Diff: media/base/mime_util_unittest.cc

Issue 877323009: Extracted media mime type checks from net/base/ into media/base/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Build fixes #1 Created 5 years, 10 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
Index: media/base/mime_util_unittest.cc
diff --git a/media/base/mime_util_unittest.cc b/media/base/mime_util_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cca80c8fee89791f253ec3eec2c55512bdda2d88
--- /dev/null
+++ b/media/base/mime_util_unittest.cc
@@ -0,0 +1,154 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/basictypes.h"
+#include "base/strings/string_split.h"
+#include "base/strings/utf_string_conversions.h"
+#include "media/base/mime_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+#if defined(OS_ANDROID)
+#include "base/android/build_info.h"
+#endif
+
+namespace media {
+
+TEST(MimeUtilTest, LookupTypes) {
+#if defined(OS_ANDROID)
+ EXPECT_TRUE(IsSupportedMediaMimeType("application/vnd.apple.mpegurl"));
+ EXPECT_TRUE(IsSupportedMediaMimeType("application/x-mpegurl"));
+ EXPECT_TRUE(IsSupportedMediaMimeType("Application/X-MPEGURL"));
+#endif
+}
+
+TEST(MimeUtilTest, StrictMediaMimeType) {
+ EXPECT_TRUE(IsStrictMediaMimeType("video/webm"));
+ EXPECT_TRUE(IsStrictMediaMimeType("Video/WEBM"));
+ EXPECT_TRUE(IsStrictMediaMimeType("audio/webm"));
+
+ EXPECT_TRUE(IsStrictMediaMimeType("audio/wav"));
+ EXPECT_TRUE(IsStrictMediaMimeType("audio/x-wav"));
+
+ EXPECT_TRUE(IsStrictMediaMimeType("video/ogg"));
+ EXPECT_TRUE(IsStrictMediaMimeType("audio/ogg"));
+ EXPECT_TRUE(IsStrictMediaMimeType("application/ogg"));
+
+ EXPECT_TRUE(IsStrictMediaMimeType("audio/mpeg"));
+ EXPECT_TRUE(IsStrictMediaMimeType("audio/mp3"));
+ EXPECT_TRUE(IsStrictMediaMimeType("audio/x-mp3"));
+
+ EXPECT_TRUE(IsStrictMediaMimeType("video/mp4"));
+ EXPECT_TRUE(IsStrictMediaMimeType("video/x-m4v"));
+ EXPECT_TRUE(IsStrictMediaMimeType("audio/mp4"));
+ EXPECT_TRUE(IsStrictMediaMimeType("audio/x-m4a"));
+
+ EXPECT_TRUE(IsStrictMediaMimeType("application/x-mpegurl"));
+ EXPECT_TRUE(IsStrictMediaMimeType("application/vnd.apple.mpegurl"));
+
+ EXPECT_FALSE(IsStrictMediaMimeType("video/unknown"));
+ EXPECT_FALSE(IsStrictMediaMimeType("Video/UNKNOWN"));
+ EXPECT_FALSE(IsStrictMediaMimeType("audio/unknown"));
+ EXPECT_FALSE(IsStrictMediaMimeType("application/unknown"));
+ EXPECT_FALSE(IsStrictMediaMimeType("unknown/unknown"));
+}
+
+TEST(MimeUtilTest, CommonMediaMimeType) {
+#if defined(OS_ANDROID)
+ bool HLSSupported;
+ if (base::android::BuildInfo::GetInstance()->sdk_int() < 14)
+ HLSSupported = false;
+ else
+ HLSSupported = true;
+#endif
+
+ EXPECT_TRUE(IsSupportedMediaMimeType("audio/webm"));
+ EXPECT_TRUE(IsSupportedMediaMimeType("video/webm"));
+
+ EXPECT_TRUE(IsSupportedMediaMimeType("audio/wav"));
+ EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-wav"));
+
+ EXPECT_TRUE(IsSupportedMediaMimeType("audio/ogg"));
+ EXPECT_TRUE(IsSupportedMediaMimeType("application/ogg"));
+#if defined(OS_ANDROID)
+ EXPECT_FALSE(IsSupportedMediaMimeType("video/ogg"));
+ EXPECT_EQ(HLSSupported, IsSupportedMediaMimeType("application/x-mpegurl"));
+ EXPECT_EQ(HLSSupported,
+ IsSupportedMediaMimeType("application/vnd.apple.mpegurl"));
+#else
+ EXPECT_TRUE(IsSupportedMediaMimeType("video/ogg"));
+ EXPECT_FALSE(IsSupportedMediaMimeType("application/x-mpegurl"));
+ EXPECT_FALSE(IsSupportedMediaMimeType("application/vnd.apple.mpegurl"));
+#endif // OS_ANDROID
+
+#if defined(USE_PROPRIETARY_CODECS)
+ EXPECT_TRUE(IsSupportedMediaMimeType("audio/mp4"));
+ EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-m4a"));
+ EXPECT_TRUE(IsSupportedMediaMimeType("video/mp4"));
+ EXPECT_TRUE(IsSupportedMediaMimeType("video/x-m4v"));
+
+ EXPECT_TRUE(IsSupportedMediaMimeType("audio/mp3"));
+ EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-mp3"));
+ EXPECT_TRUE(IsSupportedMediaMimeType("audio/mpeg"));
+ EXPECT_TRUE(IsSupportedMediaMimeType("audio/aac"));
+
+#if defined(ENABLE_MPEG2TS_STREAM_PARSER)
+ EXPECT_TRUE(IsSupportedMediaMimeType("video/mp2t"));
+#else
+ EXPECT_FALSE(IsSupportedMediaMimeType("video/mp2t"));
+#endif
+#else
+ EXPECT_FALSE(IsSupportedMediaMimeType("audio/mp4"));
+ EXPECT_FALSE(IsSupportedMediaMimeType("audio/x-m4a"));
+ EXPECT_FALSE(IsSupportedMediaMimeType("video/mp4"));
+ EXPECT_FALSE(IsSupportedMediaMimeType("video/x-m4v"));
+
+ EXPECT_FALSE(IsSupportedMediaMimeType("audio/mp3"));
+ EXPECT_FALSE(IsSupportedMediaMimeType("audio/x-mp3"));
+ EXPECT_FALSE(IsSupportedMediaMimeType("audio/mpeg"));
+ EXPECT_FALSE(IsSupportedMediaMimeType("audio/aac"));
+#endif // USE_PROPRIETARY_CODECS
+ EXPECT_FALSE(IsSupportedMediaMimeType("video/mp3"));
+
+ EXPECT_FALSE(IsSupportedMediaMimeType("video/unknown"));
+ EXPECT_FALSE(IsSupportedMediaMimeType("audio/unknown"));
+ EXPECT_FALSE(IsSupportedMediaMimeType("unknown/unknown"));
+}
+
+// Note: codecs should only be a list of 2 or fewer; hence the restriction of
+// results' length to 2.
+TEST(MimeUtilTest, ParseCodecString) {
+ const struct {
+ const char* const original;
+ size_t expected_size;
+ const char* const results[2];
+ } tests[] = {
+ { "\"bogus\"", 1, { "bogus" } },
+ { "0", 1, { "0" } },
+ { "avc1.42E01E, mp4a.40.2", 2, { "avc1", "mp4a" } },
+ { "\"mp4v.20.240, mp4a.40.2\"", 2, { "mp4v", "mp4a" } },
+ { "mp4v.20.8, samr", 2, { "mp4v", "samr" } },
+ { "\"theora, vorbis\"", 2, { "theora", "vorbis" } },
+ { "", 0, { } },
+ { "\"\"", 0, { } },
+ { "\" \"", 0, { } },
+ { ",", 2, { "", "" } },
+ };
+
+ for (size_t i = 0; i < arraysize(tests); ++i) {
+ std::vector<std::string> codecs_out;
+ ParseCodecString(tests[i].original, &codecs_out, true);
+ ASSERT_EQ(tests[i].expected_size, codecs_out.size());
+ for (size_t j = 0; j < tests[i].expected_size; ++j)
+ EXPECT_EQ(tests[i].results[j], codecs_out[j]);
+ }
+
+ // Test without stripping the codec type.
+ std::vector<std::string> codecs_out;
+ ParseCodecString("avc1.42E01E, mp4a.40.2", &codecs_out, false);
+ ASSERT_EQ(2u, codecs_out.size());
+ EXPECT_EQ("avc1.42E01E", codecs_out[0]);
+ EXPECT_EQ("mp4a.40.2", codecs_out[1]);
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698