// 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 "build/build_config.h" #include "media/base/mime_util.h" #include "testing/gtest/include/gtest/gtest.h" namespace media { 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) { 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")); #else EXPECT_TRUE(IsSupportedMediaMimeType("video/ogg")); #endif // OS_ANDROID #if defined(OS_ANDROID) // HLS is supported on Android API level 14 and higher and Chrome supports // API levels 15 and higher, so these are expected to be supported. bool kHlsSupported = true; #else bool kHlsSupported = false; #endif EXPECT_EQ(kHlsSupported, IsSupportedMediaMimeType("application/x-mpegurl")); EXPECT_EQ(kHlsSupported, IsSupportedMediaMimeType("Application/X-MPEGURL")); EXPECT_EQ(kHlsSupported, IsSupportedMediaMimeType( "application/vnd.apple.mpegurl")); #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 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 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