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 34a2ea3a33aff50c604ee4e62752191749566c0f..28b6a6422127d559e8643156c0f6d3fa59038587 100644 |
| --- a/media/base/mime_util_unittest.cc |
| +++ b/media/base/mime_util_unittest.cc |
| @@ -5,13 +5,107 @@ |
| #include <stddef.h> |
| #include "base/macros.h" |
| +#include "base/strings/stringprintf.h" |
| #include "base/strings/string_split.h" |
| #include "build/build_config.h" |
| #include "media/base/mime_util.h" |
| +#include "media/base/mime_util_internal.h" |
| #include "media/media_features.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace media { |
| +namespace internal { |
| + |
| +const bool kTestStates[] = {true, false}; |
| + |
| +// Helper method for creating a multi-value vector of |kTestStates| or a single |
| +// value vector contining |initial_value|. |
| +static std::vector<bool> CreateTestVector(bool use_default, |
|
ddorwin
2016/02/18 20:37:45
s/use_default/check_all_values/?
DaleCurtis
2016/02/19 01:35:47
Done. |test_all_values|
|
| + bool initial_value) { |
|
ddorwin
2016/02/18 20:37:45
s/initial_value/single_value/ or something like th
DaleCurtis
2016/02/19 01:35:47
Done.
|
| + if (use_default) |
| + return std::vector<bool>(kTestStates, kTestStates + arraysize(kTestStates)); |
| + return std::vector<bool>(1, initial_value); |
| +} |
| + |
| +// Helper method for running IsCodecSupportedOnAndroid() tests which will |
|
ddorwin
2016/02/18 20:37:45
nit:s/which/that/
DaleCurtis
2016/02/19 01:35:47
Done.
|
| +// iterate over all possible field values for a MimeUtil::PlatformInfo struct. |
| +// |
| +// To request a field be varied, set its value to true in the |states_to_vary| |
| +// struct. If false, the only value tested will be the field value from |
| +// |initial_state|. |
|
ddorwin
2016/02/18 20:37:45
ditto on "initial"
DaleCurtis
2016/02/19 01:35:47
Went with |test_state|
|
| +// |
| +// |test_func| should have the signature <void(const MimeUtil&, const |
| +// MimeUtil::PlatformInfo&, MimeUtil::Codec)>. |
| +template <typename TestCallback> |
| +static void RunCodecSupportTest(const MimeUtil::PlatformInfo& initial_state, |
| + const MimeUtil::PlatformInfo& states_to_vary, |
| + TestCallback test_func) { |
| + // Stuff states to test into vectors for easy for_each() iteration. |
| + std::vector<bool> has_platform_decoders_states = |
|
ddorwin
2016/02/18 20:37:45
Not that we should, but it seems that using a macr
DaleCurtis
2016/02/19 01:35:47
Helps a lot, done.
|
| + CreateTestVector(states_to_vary.has_platform_decoders, |
| + initial_state.has_platform_decoders); |
| + std::vector<bool> supports_encrypted_vp8_states = |
| + CreateTestVector(states_to_vary.supports_encrypted_vp8, |
| + initial_state.supports_encrypted_vp8); |
| + std::vector<bool> supports_opus_states = CreateTestVector( |
| + states_to_vary.supports_opus, initial_state.supports_opus); |
| + std::vector<bool> supports_vp9_states = |
| + CreateTestVector(states_to_vary.supports_vp9, initial_state.supports_vp9); |
| + std::vector<bool> using_unified_media_pipeline_states = |
| + CreateTestVector(states_to_vary.using_unified_media_pipeline, |
| + initial_state.using_unified_media_pipeline); |
| + |
| + MimeUtil mime_util; |
| + MimeUtil::PlatformInfo info; |
| + for (bool has_platform_decoders : has_platform_decoders_states) { |
| + info.has_platform_decoders = has_platform_decoders; |
| + for (bool supports_encrypted_vp8 : supports_encrypted_vp8_states) { |
| + info.supports_encrypted_vp8 = supports_encrypted_vp8; |
| + for (bool supports_opus : supports_opus_states) { |
| + info.supports_opus = supports_opus; |
| + for (bool supports_vp9 : supports_vp9_states) { |
| + info.supports_vp9 = supports_vp9; |
| + for (bool using_unified_media_pipeline : |
| + using_unified_media_pipeline_states) { |
| + info.using_unified_media_pipeline = using_unified_media_pipeline; |
| + mime_util.SetPlatformInfoForTests(info); |
| + for (int codec = MimeUtil::INVALID_CODEC; |
| + codec <= MimeUtil::LAST_CODEC; ++codec) { |
| + SCOPED_TRACE(base::StringPrintf( |
| + "has_platform_decoders=%d, supports_encrypted_vp8=%d, " |
| + "supports_opus=%d, " |
| + "supports_vp9=%d, using_unified_media_pipeline=%d, codec=%d", |
| + info.has_platform_decoders, info.supports_encrypted_vp8, |
| + info.supports_opus, info.supports_vp9, |
| + info.using_unified_media_pipeline, codec)); |
| + test_func(mime_util, info, static_cast<MimeUtil::Codec>(codec)); |
| + } |
| + } |
| + } |
| + } |
| + } |
| + } |
| +} |
| + |
| +// Helper method for generating the |states_to_vary| value used by |
| +// RunPlatformCodecTest(). Marks all fields to be varied. |
| +static MimeUtil::PlatformInfo VaryAllFields() { |
| + MimeUtil::PlatformInfo states_to_vary; |
| + states_to_vary.supports_encrypted_vp8 = true; |
| + states_to_vary.supports_opus = true; |
| + states_to_vary.supports_vp9 = true; |
| + states_to_vary.using_unified_media_pipeline = true; |
| + states_to_vary.has_platform_decoders = true; |
| + return states_to_vary; |
| +} |
| + |
| +static bool HasHevcSupport() { |
| +#if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| + return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; |
|
ddorwin
2016/02/18 20:37:45
Needs OS_ANDROID guard.
Also, there are non-Androi
DaleCurtis
2016/02/19 01:35:47
Done.
|
| +#else |
| + return false; |
| +#endif |
| +} |
| TEST(MimeUtilTest, CommonMediaMimeType) { |
| EXPECT_TRUE(IsSupportedMediaMimeType("audio/webm")); |
| @@ -111,4 +205,224 @@ TEST(MimeUtilTest, ParseCodecString) { |
| EXPECT_EQ("mp4a.40.2", codecs_out[1]); |
| } |
| +TEST(IsCodecSupportedOnAndroidTest, EncryptedCodecsFailWithoutPlatformSupport) { |
| + // Vary all parameters except |has_platform_decoders|. |
| + MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); |
| + states_to_vary.has_platform_decoders = false; |
| + |
| + // Disable platform decoders. |
| + MimeUtil::PlatformInfo initial_state; |
| + initial_state.has_platform_decoders = false; |
| + |
| + // Every codec should fail since platform support is missing and we've |
| + // requested encrypted codecs. |
| + RunCodecSupportTest( |
| + initial_state, states_to_vary, |
| + [](const MimeUtil& mime_util, const MimeUtil::PlatformInfo& info, |
| + MimeUtil::Codec codec) { |
| + EXPECT_FALSE( |
| + mime_util.IsCodecSupportedOnAndroidForTests(codec, "", true)); |
| + }); |
| +} |
| + |
| +TEST(IsCodecSupportedOnAndroidTest, EncryptedCodecBehavior) { |
| + // Vary all parameters except |has_platform_decoders|. |
| + MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); |
| + states_to_vary.has_platform_decoders = false; |
| + |
| + // Enable platform decoders. |
| + MimeUtil::PlatformInfo initial_state; |
| + initial_state.has_platform_decoders = true; |
| + |
| + RunCodecSupportTest( |
| + initial_state, states_to_vary, |
| + [](const MimeUtil& mime_util, const MimeUtil::PlatformInfo& info, |
| + MimeUtil::Codec codec) { |
| + switch (codec) { |
| + // These codecs are never supported on Android. |
|
ddorwin
2016/02/18 20:37:45
... by the Android platform.
DaleCurtis
2016/02/19 01:35:47
Done.
|
| + case MimeUtil::AC3: |
| + case MimeUtil::EAC3: |
| + case MimeUtil::INVALID_CODEC: |
|
ddorwin
2016/02/18 20:37:45
This should be first.
DaleCurtis
2016/02/19 01:35:47
Done.
|
| + case MimeUtil::MPEG2_AAC_LC: |
| + case MimeUtil::MPEG2_AAC_MAIN: |
| + case MimeUtil::MPEG2_AAC_SSR: |
| + case MimeUtil::THEORA: |
| + EXPECT_FALSE( |
| + mime_util.IsCodecSupportedOnAndroidForTests(codec, "", true)); |
| + break; |
| + |
| + // These codecs are always available with platform decoder support. |
| + case MimeUtil::H264: |
|
ddorwin
2016/02/18 20:37:45
video after audio
DaleCurtis
2016/02/19 01:35:47
Done.
|
| + case MimeUtil::PCM: |
| + case MimeUtil::MP3: |
| + case MimeUtil::MPEG4_AAC_LC: |
| + case MimeUtil::MPEG4_AAC_SBR_v1: |
| + case MimeUtil::MPEG4_AAC_SBR_PS_v2: |
| + case MimeUtil::VORBIS: |
| + EXPECT_TRUE( |
| + mime_util.IsCodecSupportedOnAndroidForTests(codec, "", true)); |
| + break; |
| + |
| + // The remaining codecs are not available on all platforms even when |
| + // a platform decoder is available. |
| + case MimeUtil::OPUS: |
| + EXPECT_EQ( |
| + info.supports_opus, |
| + mime_util.IsCodecSupportedOnAndroidForTests(codec, "", true)); |
| + break; |
| + |
| + case MimeUtil::VP8: |
| + EXPECT_EQ( |
| + info.supports_encrypted_vp8, |
| + mime_util.IsCodecSupportedOnAndroidForTests(codec, "", true)); |
| + break; |
| + |
| + case MimeUtil::VP9: |
| + EXPECT_EQ( |
| + info.supports_vp9, |
| + mime_util.IsCodecSupportedOnAndroidForTests(codec, "", true)); |
| + break; |
| + |
| + case MimeUtil::HEVC_MAIN: |
| + EXPECT_EQ( |
| + HasHevcSupport(), |
| + mime_util.IsCodecSupportedOnAndroidForTests(codec, "", true)); |
| + break; |
| + } |
| + }); |
| +} |
| + |
| +TEST(IsCodecSupportedOnAndroidTest, ClearCodecBehaviorWithAndroidPipeline) { |
| + // Vary all parameters except |using_unified_media_pipeline|. |
| + MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); |
| + states_to_vary.using_unified_media_pipeline = false; |
| + |
| + // Disable the unified pipeline. |
| + MimeUtil::PlatformInfo initial_state; |
| + initial_state.using_unified_media_pipeline = false; |
| + |
| + RunCodecSupportTest( |
| + initial_state, states_to_vary, |
| + [](const MimeUtil& mime_util, const MimeUtil::PlatformInfo& info, |
| + MimeUtil::Codec codec) { |
| + switch (codec) { |
| + // These codecs are never supported on Android. |
|
ddorwin
2016/02/18 20:37:45
ditto (at least similar)
DaleCurtis
2016/02/19 01:35:47
Done.
|
| + case MimeUtil::AC3: |
| + case MimeUtil::EAC3: |
| + case MimeUtil::INVALID_CODEC: |
|
ddorwin
2016/02/18 20:37:45
ditto
DaleCurtis
2016/02/19 01:35:47
Done.
|
| + case MimeUtil::MPEG2_AAC_LC: |
| + case MimeUtil::MPEG2_AAC_MAIN: |
| + case MimeUtil::MPEG2_AAC_SSR: |
| + case MimeUtil::THEORA: |
| + EXPECT_FALSE( |
| + mime_util.IsCodecSupportedOnAndroidForTests(codec, "", false)); |
| + break; |
| + |
| + // These codecs are always available. |
|
ddorwin
2016/02/18 20:37:45
... via MediaPlayer.
DaleCurtis
2016/02/19 01:35:47
Done.
|
| + case MimeUtil::H264: |
|
ddorwin
2016/02/18 20:37:45
ditto
DaleCurtis
2016/02/19 01:35:47
Done.
|
| + case MimeUtil::PCM: |
| + case MimeUtil::MP3: |
| + case MimeUtil::MPEG4_AAC_LC: |
| + case MimeUtil::MPEG4_AAC_SBR_v1: |
| + case MimeUtil::MPEG4_AAC_SBR_PS_v2: |
| + case MimeUtil::VORBIS: |
| + case MimeUtil::VP8: |
| + EXPECT_TRUE( |
| + mime_util.IsCodecSupportedOnAndroidForTests(codec, "", false)); |
| + break; |
| + |
| + // The remaining codecs depend on the platform version. |
| + case MimeUtil::OPUS: |
| + EXPECT_EQ( |
| + info.supports_opus, |
| + mime_util.IsCodecSupportedOnAndroidForTests(codec, "", false)); |
| + break; |
| + |
| + case MimeUtil::VP9: |
| + EXPECT_EQ( |
| + info.supports_vp9, |
| + mime_util.IsCodecSupportedOnAndroidForTests(codec, "", false)); |
| + break; |
| + |
| + case MimeUtil::HEVC_MAIN: |
| + EXPECT_EQ( |
| + HasHevcSupport(), |
| + mime_util.IsCodecSupportedOnAndroidForTests(codec, "", false)); |
| + break; |
| + } |
| + }); |
| +} |
| + |
| +TEST(IsCodecSupportedOnAndroidTest, ClearCodecBehaviorWithUnifiedPipeline) { |
| + // Vary all parameters except |using_unified_media_pipeline|. |
| + MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); |
| + states_to_vary.using_unified_media_pipeline = false; |
| + |
| + // Enable the unified pipeline. |
| + MimeUtil::PlatformInfo initial_state; |
| + initial_state.using_unified_media_pipeline = true; |
| + |
| + RunCodecSupportTest( |
| + initial_state, states_to_vary, |
| + [](const MimeUtil& mime_util, const MimeUtil::PlatformInfo& info, |
| + MimeUtil::Codec codec) { |
| + switch (codec) { |
| + // These codecs are never supported on Android. |
| + case MimeUtil::AC3: |
| + case MimeUtil::EAC3: |
| + case MimeUtil::INVALID_CODEC: |
| + case MimeUtil::THEORA: |
| + EXPECT_FALSE( |
| + mime_util.IsCodecSupportedOnAndroidForTests(codec, "", false)); |
| + break; |
| + |
| + // These codecs are always supported with the unified pipeline. |
| + case MimeUtil::PCM: |
| + case MimeUtil::MPEG2_AAC_LC: |
| + case MimeUtil::MPEG2_AAC_MAIN: |
| + case MimeUtil::MPEG2_AAC_SSR: |
| + case MimeUtil::MP3: |
| + case MimeUtil::MPEG4_AAC_LC: |
| + case MimeUtil::MPEG4_AAC_SBR_v1: |
| + case MimeUtil::MPEG4_AAC_SBR_PS_v2: |
| + case MimeUtil::OPUS: |
| + case MimeUtil::VORBIS: |
| + case MimeUtil::VP8: |
| + case MimeUtil::VP9: |
| + EXPECT_TRUE( |
| + mime_util.IsCodecSupportedOnAndroidForTests(codec, "", false)); |
| + break; |
| + |
| + // These codecs are only supported if platform decoders are supported. |
| + case MimeUtil::H264: |
| + EXPECT_EQ( |
| + info.has_platform_decoders, |
| + mime_util.IsCodecSupportedOnAndroidForTests(codec, "", false)); |
| + break; |
| + |
| + case MimeUtil::HEVC_MAIN: |
| + EXPECT_EQ( |
| + HasHevcSupport() && info.has_platform_decoders, |
| + mime_util.IsCodecSupportedOnAndroidForTests(codec, "", false)); |
| + break; |
| + } |
| + }); |
| +} |
| + |
| +TEST(IsCodecSupportedOnAndroidTest, OpusOggSupport) { |
| + // Vary all parameters; thus use default initial state. |
| + MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); |
| + MimeUtil::PlatformInfo initial_state; |
| + |
| + RunCodecSupportTest( |
| + initial_state, states_to_vary, |
| + [](const MimeUtil& mime_util, const MimeUtil::PlatformInfo& info, |
| + MimeUtil::Codec codec) { |
| + EXPECT_EQ(info.using_unified_media_pipeline, |
| + mime_util.IsCodecSupportedOnAndroidForTests( |
| + MimeUtil::OPUS, "audio/ogg", false)); |
| + }); |
| +} |
| + |
| +} // namespace internal |
| } // namespace media |