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..3f2790afcb1c9bf9d9c4d94f264c02f00d8882af 100644 |
| --- a/media/base/mime_util_unittest.cc |
| +++ b/media/base/mime_util_unittest.cc |
| @@ -6,12 +6,113 @@ |
| #include "base/macros.h" |
| #include "base/strings/string_split.h" |
| +#include "base/strings/stringprintf.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" |
| +#if defined(OS_ANDROID) |
| +#include "base/android/build_info.h" |
| +#endif |
| + |
| namespace media { |
| +namespace internal { |
| + |
| +const char kTestMimeType[] = "foo/foo"; |
|
ddorwin
2016/02/19 19:53:23
Suggest:
// Type is ignored in nearly all cases.
DaleCurtis
2016/02/19 20:28:35
Done with some further elaboration.
|
| + |
| +// Helper method for creating a multi-value vector of |kTestStates| if |
| +// |test_all_values| is true or if false, a single value vector containing |
| +// |single_value|. |
| +static std::vector<bool> CreateTestVector(bool test_all_values, |
| + bool single_value) { |
| + const bool kTestStates[] = {true, false}; |
| + if (test_all_values) |
| + return std::vector<bool>(kTestStates, kTestStates + arraysize(kTestStates)); |
| + return std::vector<bool>(1, single_value); |
| +} |
| + |
| +// Helper method for running IsCodecSupportedOnPlatform() tests that will |
| +// 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 |
| +// |test_state|. |
| +// |
| +// |test_func| should have the signature <void(const MimeUtil::PlatformInfo&, |
| +// MimeUtil::Codec)>. |
| +template <typename TestCallback> |
| +static void RunCodecSupportTest(const MimeUtil::PlatformInfo& test_state, |
|
ddorwin
2016/02/19 19:53:23
state*s*
DaleCurtis
2016/02/19 20:28:35
Done.
|
| + const MimeUtil::PlatformInfo& states_to_vary, |
|
ddorwin
2016/02/19 19:53:23
It's strange and potentially error-prone that the
DaleCurtis
2016/02/19 20:28:35
Flipped.
|
| + TestCallback test_func) { |
| +#define MAKE_TEST_VECTOR(name) \ |
| + std::vector<bool> name##_states = \ |
| + CreateTestVector(states_to_vary.name, test_state.name) |
| + |
| + // Stuff states to test into vectors for easy for_each() iteration. |
| + MAKE_TEST_VECTOR(has_platform_decoders); |
| + MAKE_TEST_VECTOR(has_platform_vp8_decoder); |
| + MAKE_TEST_VECTOR(supports_opus); |
| + MAKE_TEST_VECTOR(supports_vp9); |
| + MAKE_TEST_VECTOR(is_unified_media_pipeline_enabled); |
| +#undef MAKE_TEST_VECTOR |
| + |
| + MimeUtil::PlatformInfo info; |
| + for (bool has_platform_decoders : has_platform_decoders_states) { |
| + info.has_platform_decoders = has_platform_decoders; |
| + for (bool has_platform_vp8_decoder : has_platform_vp8_decoder_states) { |
| + info.has_platform_vp8_decoder = has_platform_vp8_decoder; |
| + 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 is_unified_media_pipeline_enabled : |
| + is_unified_media_pipeline_enabled_states) { |
| + info.is_unified_media_pipeline_enabled = |
| + is_unified_media_pipeline_enabled; |
| + for (int codec = MimeUtil::INVALID_CODEC; |
| + codec <= MimeUtil::LAST_CODEC; ++codec) { |
| + SCOPED_TRACE(base::StringPrintf( |
| + "has_platform_decoders=%d, has_platform_vp8_decoder=%d, " |
| + "supports_opus=%d, " |
| + "supports_vp9=%d, is_unified_media_pipeline_enabled=%d, " |
| + "codec=%d", |
| + info.has_platform_decoders, info.has_platform_vp8_decoder, |
| + info.supports_opus, info.supports_vp9, |
| + info.is_unified_media_pipeline_enabled, codec)); |
| + test_func(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.has_platform_vp8_decoder = true; |
| + states_to_vary.supports_opus = true; |
| + states_to_vary.supports_vp9 = true; |
| + states_to_vary.is_unified_media_pipeline_enabled = true; |
| + states_to_vary.has_platform_decoders = true; |
| + return states_to_vary; |
| +} |
| + |
| +static bool HasHevcSupport() { |
| +#if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| +#if defined(OS_ANDROID) |
| + return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; |
| +#else |
| + return true; |
| +#endif // defined(OS_ANDROID) |
| +#else |
| + return false; |
| +#endif // BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| +} |
| TEST(MimeUtilTest, CommonMediaMimeType) { |
| EXPECT_TRUE(IsSupportedMediaMimeType("audio/webm")); |
| @@ -111,4 +212,217 @@ TEST(MimeUtilTest, ParseCodecString) { |
| EXPECT_EQ("mp4a.40.2", codecs_out[1]); |
| } |
| +TEST(IsCodecSupportedOnPlatformTest, |
| + 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 test_state; |
| + test_state.has_platform_decoders = false; |
| + |
| + // Every codec should fail since platform support is missing and we've |
| + // requested encrypted codecs. |
| + RunCodecSupportTest( |
| + test_state, states_to_vary, |
| + [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { |
| + EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform(codec, kTestMimeType, |
| + true, info)); |
| + }); |
| +} |
| + |
| +TEST(IsCodecSupportedOnPlatformTest, 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 test_state; |
| + test_state.has_platform_decoders = true; |
| + |
| + RunCodecSupportTest( |
| + test_state, states_to_vary, |
| + [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { |
| + switch (codec) { |
| + // These codecs are never supported by the Android platform. |
| + case MimeUtil::INVALID_CODEC: |
| + case MimeUtil::AC3: |
| + case MimeUtil::EAC3: |
| + case MimeUtil::MPEG2_AAC_LC: |
| + case MimeUtil::MPEG2_AAC_MAIN: |
| + case MimeUtil::MPEG2_AAC_SSR: |
| + case MimeUtil::THEORA: |
| + EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform( |
|
ddorwin
2016/02/19 19:53:23
Every call is identical for each test. Should we i
DaleCurtis
2016/02/19 20:28:35
Good suggestion, done!
|
| + codec, kTestMimeType, true, info)); |
| + break; |
| + |
| + // These codecs are always available with platform decoder support. |
| + 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::H264: |
| + EXPECT_TRUE(MimeUtil::IsCodecSupportedOnPlatform( |
| + codec, kTestMimeType, true, info)); |
| + 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, |
| + MimeUtil::IsCodecSupportedOnPlatform(codec, kTestMimeType, |
| + true, info)); |
| + break; |
| + |
| + case MimeUtil::VP8: |
| + EXPECT_EQ(info.has_platform_vp8_decoder, |
| + MimeUtil::IsCodecSupportedOnPlatform(codec, kTestMimeType, |
| + true, info)); |
| + break; |
| + |
| + case MimeUtil::VP9: |
| + EXPECT_EQ(info.supports_vp9, MimeUtil::IsCodecSupportedOnPlatform( |
| + codec, kTestMimeType, true, info)); |
| + break; |
| + |
| + case MimeUtil::HEVC_MAIN: |
| + EXPECT_EQ(HasHevcSupport(), MimeUtil::IsCodecSupportedOnPlatform( |
| + codec, kTestMimeType, true, info)); |
| + break; |
| + } |
| + }); |
| +} |
| + |
| +TEST(IsCodecSupportedOnPlatformTest, ClearCodecBehaviorWithAndroidPipeline) { |
| + // Vary all parameters except |is_unified_media_pipeline_enabled|. |
| + MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); |
| + states_to_vary.is_unified_media_pipeline_enabled = false; |
| + |
| + // Disable the unified pipeline. |
| + MimeUtil::PlatformInfo test_state; |
| + test_state.is_unified_media_pipeline_enabled = false; |
| + |
| + RunCodecSupportTest( |
| + test_state, states_to_vary, |
| + [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { |
| + switch (codec) { |
| + // These codecs are never supported by the Android platform. |
| + case MimeUtil::INVALID_CODEC: |
| + case MimeUtil::AC3: |
| + case MimeUtil::EAC3: |
| + case MimeUtil::MPEG2_AAC_LC: |
| + case MimeUtil::MPEG2_AAC_MAIN: |
| + case MimeUtil::MPEG2_AAC_SSR: |
| + case MimeUtil::THEORA: |
| + EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform( |
| + codec, kTestMimeType, false, info)); |
| + break; |
| + |
| + // These codecs are always available via MediaPlayer. |
| + 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::H264: |
| + case MimeUtil::VP8: |
| + EXPECT_TRUE(MimeUtil::IsCodecSupportedOnPlatform( |
| + codec, kTestMimeType, false, info)); |
| + break; |
| + |
| + // The remaining codecs depend on the platform version. |
| + case MimeUtil::OPUS: |
| + EXPECT_EQ(info.supports_opus, |
| + MimeUtil::IsCodecSupportedOnPlatform(codec, kTestMimeType, |
| + false, info)); |
| + break; |
| + |
| + case MimeUtil::VP9: |
| + EXPECT_EQ(info.supports_vp9, |
| + MimeUtil::IsCodecSupportedOnPlatform(codec, kTestMimeType, |
| + false, info)); |
| + break; |
| + |
| + case MimeUtil::HEVC_MAIN: |
| + EXPECT_EQ(HasHevcSupport(), MimeUtil::IsCodecSupportedOnPlatform( |
| + codec, kTestMimeType, false, info)); |
| + break; |
| + } |
| + }); |
| +} |
| + |
| +TEST(IsCodecSupportedOnPlatformTest, ClearCodecBehaviorWithUnifiedPipeline) { |
| + // Vary all parameters except |is_unified_media_pipeline_enabled|. |
| + MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); |
| + states_to_vary.is_unified_media_pipeline_enabled = false; |
| + |
| + // Enable the unified pipeline. |
| + MimeUtil::PlatformInfo test_state; |
| + test_state.is_unified_media_pipeline_enabled = true; |
| + |
| + RunCodecSupportTest( |
| + test_state, states_to_vary, |
| + [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { |
| + switch (codec) { |
| + // These codecs are never supported by the Android platform. |
| + case MimeUtil::INVALID_CODEC: |
| + case MimeUtil::AC3: |
| + case MimeUtil::EAC3: |
| + case MimeUtil::THEORA: |
| + EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform( |
| + codec, kTestMimeType, false, info)); |
| + 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(MimeUtil::IsCodecSupportedOnPlatform( |
| + codec, kTestMimeType, false, info)); |
| + break; |
| + |
| + // These codecs are only supported if platform decoders are supported. |
| + case MimeUtil::H264: |
| + EXPECT_EQ(info.has_platform_decoders, |
| + MimeUtil::IsCodecSupportedOnPlatform(codec, kTestMimeType, |
| + false, info)); |
| + break; |
| + |
| + case MimeUtil::HEVC_MAIN: |
| + EXPECT_EQ(HasHevcSupport() && info.has_platform_decoders, |
| + MimeUtil::IsCodecSupportedOnPlatform(codec, kTestMimeType, |
| + false, info)); |
| + break; |
| + } |
| + }); |
| +} |
| + |
| +TEST(IsCodecSupportedOnPlatformTest, OpusOggSupport) { |
| + // Vary all parameters; thus use default initial state. |
| + MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); |
| + MimeUtil::PlatformInfo test_state; |
| + |
| + RunCodecSupportTest( |
| + test_state, states_to_vary, |
| + [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { |
| + EXPECT_EQ(info.is_unified_media_pipeline_enabled, |
| + MimeUtil::IsCodecSupportedOnPlatform( |
| + MimeUtil::OPUS, "audio/ogg", false, info)); |
| + }); |
| +} |
| + |
| +} // namespace internal |
| } // namespace media |