Chromium Code Reviews| Index: media/base/mime_util_unittest.cc |
| diff --git a/media/base/mime_util_unittest.cc b/media/base/mime_util_unittest.cc |
| index efc86d161a4fc37cf19b84968533cfd4844349cd..9b84b541256d8e0b6454ef27bb74b2844ca89915 100644 |
| --- a/media/base/mime_util_unittest.cc |
| +++ b/media/base/mime_util_unittest.cc |
| @@ -9,10 +9,13 @@ |
| #include "base/strings/stringprintf.h" |
| #include "base/test/scoped_command_line.h" |
| #include "build/build_config.h" |
| +#include "media/base/audio_codecs.h" |
| #include "media/base/media.h" |
| #include "media/base/media_switches.h" |
| #include "media/base/mime_util.h" |
| #include "media/base/mime_util_internal.h" |
| +#include "media/base/video_codecs.h" |
| +#include "media/base/video_color_space.h" |
| #include "media/media_features.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -234,9 +237,106 @@ TEST(MimeUtilTest, SplitCodecsToVector) { |
| EXPECT_EQ("mp4a.40.2", codecs_out[1]); |
| } |
| +// Basic smoke test for API. More exhaustive codec string testing found in |
| +// media_canplaytype_browsertest.cc. |
| +TEST(MimeUtilTest, ParseVideoCodecString) { |
| + bool out_is_ambiguous; |
| + VideoCodec out_codec; |
| + VideoCodecProfile out_profile; |
| + uint8_t out_level; |
| + VideoColorSpace out_colorspace; |
| + |
| + // Valid AVC string. |
| + EXPECT_TRUE(ParseVideoCodecString("video/mp4", "avc3.42E01E", |
| + &out_is_ambiguous, &out_codec, &out_profile, |
| + &out_level, &out_colorspace)); |
| + EXPECT_FALSE(out_is_ambiguous); |
| + EXPECT_EQ(kCodecH264, out_codec); |
| + EXPECT_EQ(H264PROFILE_BASELINE, out_profile); |
| + EXPECT_EQ(30, out_level); |
| + EXPECT_EQ(VideoColorSpace::REC709(), out_colorspace); |
| + |
| + // Valid VP9 string. |
| + EnableNewVp9CodecStringSupport(); |
| + EXPECT_TRUE(ParseVideoCodecString("video/webm", "vp09.00.10.08", |
| + &out_is_ambiguous, &out_codec, &out_profile, |
| + &out_level, &out_colorspace)); |
| + EXPECT_FALSE(out_is_ambiguous); |
| + EXPECT_EQ(kCodecVP9, out_codec); |
| + EXPECT_EQ(VP9PROFILE_PROFILE0, out_profile); |
| + EXPECT_EQ(10, out_level); |
| + EXPECT_EQ(VideoColorSpace::REC709(), out_colorspace); |
| + // Restore to avoid polluting other tests. |
| + DisableNewVp9CodecStringSupport_ForTesting(); |
| + |
| + // Ambiguous AVC string. |
| + EXPECT_TRUE(ParseVideoCodecString("video/mp4", "avc3", &out_is_ambiguous, |
| + &out_codec, &out_profile, &out_level, |
| + &out_colorspace)); |
| + EXPECT_TRUE(out_is_ambiguous); |
| + EXPECT_EQ(kCodecH264, out_codec); |
| + EXPECT_EQ(VIDEO_CODEC_PROFILE_UNKNOWN, out_profile); |
| + EXPECT_EQ(0, out_level); |
| + EXPECT_EQ(VideoColorSpace::REC709(), out_colorspace); |
|
tguilbert
2017/05/17 20:58:33
Can you add a UT for a out_colorspace that isn't R
chcunningham
2017/05/18 01:29:42
Done.
|
| + |
| + // Audio codecs codec is not valid for video API. |
| + EXPECT_FALSE(ParseVideoCodecString("video/mp4", "aac", &out_is_ambiguous, |
| + &out_codec, &out_profile, &out_level, |
| + &out_colorspace)); |
| + |
| + // Made up codec is invalid. |
| + EXPECT_FALSE(ParseVideoCodecString("video/mp4", "bogus", &out_is_ambiguous, |
| + &out_codec, &out_profile, &out_level, |
| + &out_colorspace)); |
| +} |
| + |
| +TEST(MimeUtilTest, ParseAudioCodecString) { |
| + bool out_is_ambiguous; |
| + AudioCodec out_codec; |
| + |
| + // Valid Opus string. |
| + EXPECT_TRUE(ParseAudioCodecString("audio/webm", "opus", &out_is_ambiguous, |
| + &out_codec)); |
| + EXPECT_FALSE(out_is_ambiguous); |
| + EXPECT_EQ(kCodecOpus, out_codec); |
| + |
| + // Valid AAC string. |
| + EXPECT_TRUE(ParseAudioCodecString("audio/mp4", "mp4a.40.2", &out_is_ambiguous, |
| + &out_codec)); |
| + EXPECT_FALSE(out_is_ambiguous); |
| + EXPECT_EQ(kCodecAAC, out_codec); |
| + |
| + // Ambiguous AAC string. |
| + // TODO(chcunningha): This can probably be allowed. I think We treat all |
| + // MPEG4_AAC the same. |
| + EXPECT_TRUE(ParseAudioCodecString("audio/mp4", "mp4a.40", &out_is_ambiguous, |
| + &out_codec)); |
| + EXPECT_TRUE(out_is_ambiguous); |
| + EXPECT_EQ(kCodecAAC, out_codec); |
| + |
| + // Valid empty codec string. Codec unambiguously implied by mime type. |
| + EXPECT_TRUE( |
| + ParseAudioCodecString("audio/flac", "", &out_is_ambiguous, &out_codec)); |
| + EXPECT_FALSE(out_is_ambiguous); |
| + EXPECT_EQ(kCodecFLAC, out_codec); |
| + |
| + // Valid audio codec should still be allowed with video mime type. |
| + EXPECT_TRUE(ParseAudioCodecString("video/webm", "opus", &out_is_ambiguous, |
| + &out_codec)); |
| + EXPECT_FALSE(out_is_ambiguous); |
| + EXPECT_EQ(kCodecOpus, out_codec); |
| + |
| + // Video codec is not valid for audio API. |
| + EXPECT_FALSE(ParseAudioCodecString("audio/webm", "vp09.00.10.08", |
| + &out_is_ambiguous, &out_codec)); |
| + |
| + // Made up codec is also not valid. |
| + EXPECT_FALSE(ParseAudioCodecString("audio/webm", "bogus", &out_is_ambiguous, |
| + &out_codec)); |
| +} |
| + |
| // See deeper string parsing testing in video_codecs_unittests.cc. |
| TEST(MimeUtilTest, ExperimentalMultiPartVp9) { |
| - base::test::ScopedCommandLine scoped_command_line; |
| // Multi-part VP9 string not enabled by default. |
| EXPECT_FALSE(IsSupportedMediaFormat("video/webm", {"vp09.00.10.08"})); |
| @@ -244,6 +344,8 @@ TEST(MimeUtilTest, ExperimentalMultiPartVp9) { |
| // Should work if enabled. |
| EnableNewVp9CodecStringSupport(); |
| EXPECT_TRUE(IsSupportedMediaFormat("video/webm", {"vp09.00.10.08"})); |
| + // Restore to avoid polluting other tests. |
| + DisableNewVp9CodecStringSupport_ForTesting(); |
| } |
| TEST(IsCodecSupportedOnAndroidTest, EncryptedCodecsFailWithoutPlatformSupport) { |