| 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..b1f190384eaf42bcb77f492f7d7f313e600518bc
|
| --- /dev/null
|
| +++ b/media/base/mime_util_unittest.cc
|
| @@ -0,0 +1,136 @@
|
| +// Copyright 2014 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, StrictMediaMimeType) {
|
| + 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("audio/unknown"));
|
| + EXPECT_FALSE(IsStrictMediaMimeType("application/unknown"));
|
| + EXPECT_FALSE(IsStrictMediaMimeType("unknown/unknown"));
|
| +}
|
| +
|
| +TEST(MimeUtilTest, CommonMediaMimeType) {
|
| +#if defined(OS_ANDROID)
|
| + bool hls_supported;
|
| + if (base::android::BuildInfo::GetInstance()->sdk_int() < 14)
|
| + hls_supported = false;
|
| + else
|
| + hls_supported = 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(hls_supported, IsSupportedMediaMimeType("application/x-mpegurl"));
|
| + EXPECT_EQ(hls_supported,
|
| + 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"));
|
| +#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"));
|
| +#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* original;
|
| + size_t expected_size;
|
| + const char* 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_UNSAFE(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
|
|
|