Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/basictypes.h" | |
| 6 #include "base/strings/string_split.h" | |
| 7 #include "media/base/mime_util.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 #if defined(OS_ANDROID) | |
| 11 #include "base/android/build_info.h" | |
| 12 #endif | |
| 13 | |
| 14 namespace media { | |
| 15 | |
| 16 TEST(MimeUtilTest, LookupTypes) { | |
|
Ryan Sleevi
2015/05/06 00:59:12
CLEANUP: Nothing for non-Android here? ;)
Should
servolk
2015/05/06 01:13:39
Yep, but it was like that in net/base/mime_util_un
| |
| 17 #if defined(OS_ANDROID) | |
| 18 EXPECT_TRUE(IsSupportedMediaMimeType("application/vnd.apple.mpegurl")); | |
| 19 EXPECT_TRUE(IsSupportedMediaMimeType("application/x-mpegurl")); | |
| 20 EXPECT_TRUE(IsSupportedMediaMimeType("Application/X-MPEGURL")); | |
| 21 #endif | |
| 22 } | |
| 23 | |
| 24 TEST(MimeUtilTest, StrictMediaMimeType) { | |
| 25 EXPECT_TRUE(IsStrictMediaMimeType("video/webm")); | |
| 26 EXPECT_TRUE(IsStrictMediaMimeType("Video/WEBM")); | |
| 27 EXPECT_TRUE(IsStrictMediaMimeType("audio/webm")); | |
| 28 | |
| 29 EXPECT_TRUE(IsStrictMediaMimeType("audio/wav")); | |
| 30 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-wav")); | |
| 31 | |
| 32 EXPECT_TRUE(IsStrictMediaMimeType("video/ogg")); | |
| 33 EXPECT_TRUE(IsStrictMediaMimeType("audio/ogg")); | |
| 34 EXPECT_TRUE(IsStrictMediaMimeType("application/ogg")); | |
| 35 | |
| 36 EXPECT_TRUE(IsStrictMediaMimeType("audio/mpeg")); | |
| 37 EXPECT_TRUE(IsStrictMediaMimeType("audio/mp3")); | |
| 38 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-mp3")); | |
| 39 | |
| 40 EXPECT_TRUE(IsStrictMediaMimeType("video/mp4")); | |
| 41 EXPECT_TRUE(IsStrictMediaMimeType("video/x-m4v")); | |
| 42 EXPECT_TRUE(IsStrictMediaMimeType("audio/mp4")); | |
| 43 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-m4a")); | |
| 44 | |
| 45 EXPECT_TRUE(IsStrictMediaMimeType("application/x-mpegurl")); | |
| 46 EXPECT_TRUE(IsStrictMediaMimeType("application/vnd.apple.mpegurl")); | |
| 47 | |
| 48 EXPECT_FALSE(IsStrictMediaMimeType("video/unknown")); | |
| 49 EXPECT_FALSE(IsStrictMediaMimeType("Video/UNKNOWN")); | |
| 50 EXPECT_FALSE(IsStrictMediaMimeType("audio/unknown")); | |
| 51 EXPECT_FALSE(IsStrictMediaMimeType("application/unknown")); | |
| 52 EXPECT_FALSE(IsStrictMediaMimeType("unknown/unknown")); | |
| 53 } | |
| 54 | |
| 55 TEST(MimeUtilTest, CommonMediaMimeType) { | |
| 56 #if defined(OS_ANDROID) | |
| 57 bool HLSSupported; | |
| 58 if (base::android::BuildInfo::GetInstance()->sdk_int() < 14) | |
| 59 HLSSupported = false; | |
| 60 else | |
| 61 HLSSupported = true; | |
| 62 #endif | |
|
Ryan Sleevi
2015/05/06 00:59:12
CLEANUP: It seems this is no longer needed, as we
servolk
2015/05/06 01:13:39
Ok, will do after this CL
servolk
2015/05/06 17:03:56
Done as a separate CL:
https://codereview.chromium
| |
| 63 | |
| 64 EXPECT_TRUE(IsSupportedMediaMimeType("audio/webm")); | |
| 65 EXPECT_TRUE(IsSupportedMediaMimeType("video/webm")); | |
| 66 | |
| 67 EXPECT_TRUE(IsSupportedMediaMimeType("audio/wav")); | |
| 68 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-wav")); | |
| 69 | |
| 70 EXPECT_TRUE(IsSupportedMediaMimeType("audio/ogg")); | |
| 71 EXPECT_TRUE(IsSupportedMediaMimeType("application/ogg")); | |
| 72 #if defined(OS_ANDROID) | |
| 73 EXPECT_FALSE(IsSupportedMediaMimeType("video/ogg")); | |
| 74 EXPECT_EQ(HLSSupported, IsSupportedMediaMimeType("application/x-mpegurl")); | |
| 75 EXPECT_EQ(HLSSupported, | |
| 76 IsSupportedMediaMimeType("application/vnd.apple.mpegurl")); | |
| 77 #else | |
| 78 EXPECT_TRUE(IsSupportedMediaMimeType("video/ogg")); | |
| 79 EXPECT_FALSE(IsSupportedMediaMimeType("application/x-mpegurl")); | |
| 80 EXPECT_FALSE(IsSupportedMediaMimeType("application/vnd.apple.mpegurl")); | |
| 81 #endif // OS_ANDROID | |
| 82 | |
| 83 #if defined(USE_PROPRIETARY_CODECS) | |
| 84 EXPECT_TRUE(IsSupportedMediaMimeType("audio/mp4")); | |
| 85 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-m4a")); | |
| 86 EXPECT_TRUE(IsSupportedMediaMimeType("video/mp4")); | |
| 87 EXPECT_TRUE(IsSupportedMediaMimeType("video/x-m4v")); | |
| 88 | |
| 89 EXPECT_TRUE(IsSupportedMediaMimeType("audio/mp3")); | |
| 90 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-mp3")); | |
| 91 EXPECT_TRUE(IsSupportedMediaMimeType("audio/mpeg")); | |
| 92 EXPECT_TRUE(IsSupportedMediaMimeType("audio/aac")); | |
| 93 | |
| 94 #if defined(ENABLE_MPEG2TS_STREAM_PARSER) | |
| 95 EXPECT_TRUE(IsSupportedMediaMimeType("video/mp2t")); | |
| 96 #else | |
| 97 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp2t")); | |
| 98 #endif | |
| 99 #else | |
| 100 EXPECT_FALSE(IsSupportedMediaMimeType("audio/mp4")); | |
| 101 EXPECT_FALSE(IsSupportedMediaMimeType("audio/x-m4a")); | |
| 102 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp4")); | |
| 103 EXPECT_FALSE(IsSupportedMediaMimeType("video/x-m4v")); | |
| 104 | |
| 105 EXPECT_FALSE(IsSupportedMediaMimeType("audio/mp3")); | |
| 106 EXPECT_FALSE(IsSupportedMediaMimeType("audio/x-mp3")); | |
| 107 EXPECT_FALSE(IsSupportedMediaMimeType("audio/mpeg")); | |
| 108 EXPECT_FALSE(IsSupportedMediaMimeType("audio/aac")); | |
| 109 #endif // USE_PROPRIETARY_CODECS | |
| 110 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp3")); | |
| 111 | |
| 112 EXPECT_FALSE(IsSupportedMediaMimeType("video/unknown")); | |
| 113 EXPECT_FALSE(IsSupportedMediaMimeType("audio/unknown")); | |
| 114 EXPECT_FALSE(IsSupportedMediaMimeType("unknown/unknown")); | |
| 115 } | |
| 116 | |
| 117 // Note: codecs should only be a list of 2 or fewer; hence the restriction of | |
| 118 // results' length to 2. | |
| 119 TEST(MimeUtilTest, ParseCodecString) { | |
| 120 const struct { | |
| 121 const char* const original; | |
| 122 size_t expected_size; | |
| 123 const char* const results[2]; | |
| 124 } tests[] = { | |
| 125 { "\"bogus\"", 1, { "bogus" } }, | |
| 126 { "0", 1, { "0" } }, | |
| 127 { "avc1.42E01E, mp4a.40.2", 2, { "avc1", "mp4a" } }, | |
| 128 { "\"mp4v.20.240, mp4a.40.2\"", 2, { "mp4v", "mp4a" } }, | |
| 129 { "mp4v.20.8, samr", 2, { "mp4v", "samr" } }, | |
| 130 { "\"theora, vorbis\"", 2, { "theora", "vorbis" } }, | |
| 131 { "", 0, { } }, | |
| 132 { "\"\"", 0, { } }, | |
| 133 { "\" \"", 0, { } }, | |
| 134 { ",", 2, { "", "" } }, | |
| 135 }; | |
| 136 | |
| 137 for (size_t i = 0; i < arraysize(tests); ++i) { | |
| 138 std::vector<std::string> codecs_out; | |
| 139 ParseCodecString(tests[i].original, &codecs_out, true); | |
| 140 ASSERT_EQ(tests[i].expected_size, codecs_out.size()); | |
| 141 for (size_t j = 0; j < tests[i].expected_size; ++j) | |
| 142 EXPECT_EQ(tests[i].results[j], codecs_out[j]); | |
| 143 } | |
| 144 | |
| 145 // Test without stripping the codec type. | |
| 146 std::vector<std::string> codecs_out; | |
| 147 ParseCodecString("avc1.42E01E, mp4a.40.2", &codecs_out, false); | |
| 148 ASSERT_EQ(2u, codecs_out.size()); | |
| 149 EXPECT_EQ("avc1.42E01E", codecs_out[0]); | |
| 150 EXPECT_EQ("mp4a.40.2", codecs_out[1]); | |
| 151 } | |
| 152 | |
| 153 } // namespace media | |
| OLD | NEW |