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 "base/strings/utf_string_conversions.h" |
| 8 #include "media/base/mime_util.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 #if defined(OS_ANDROID) |
| 12 #include "base/android/build_info.h" |
| 13 #endif |
| 14 |
| 15 namespace media { |
| 16 |
| 17 TEST(MimeUtilTest, LookupTypes) { |
| 18 #if defined(OS_ANDROID) |
| 19 EXPECT_TRUE(IsSupportedMediaMimeType("application/vnd.apple.mpegurl")); |
| 20 EXPECT_TRUE(IsSupportedMediaMimeType("application/x-mpegurl")); |
| 21 EXPECT_TRUE(IsSupportedMediaMimeType("Application/X-MPEGURL")); |
| 22 #endif |
| 23 } |
| 24 |
| 25 TEST(MimeUtilTest, StrictMediaMimeType) { |
| 26 EXPECT_TRUE(IsStrictMediaMimeType("video/webm")); |
| 27 EXPECT_TRUE(IsStrictMediaMimeType("Video/WEBM")); |
| 28 EXPECT_TRUE(IsStrictMediaMimeType("audio/webm")); |
| 29 |
| 30 EXPECT_TRUE(IsStrictMediaMimeType("audio/wav")); |
| 31 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-wav")); |
| 32 |
| 33 EXPECT_TRUE(IsStrictMediaMimeType("video/ogg")); |
| 34 EXPECT_TRUE(IsStrictMediaMimeType("audio/ogg")); |
| 35 EXPECT_TRUE(IsStrictMediaMimeType("application/ogg")); |
| 36 |
| 37 EXPECT_TRUE(IsStrictMediaMimeType("audio/mpeg")); |
| 38 EXPECT_TRUE(IsStrictMediaMimeType("audio/mp3")); |
| 39 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-mp3")); |
| 40 |
| 41 EXPECT_TRUE(IsStrictMediaMimeType("video/mp4")); |
| 42 EXPECT_TRUE(IsStrictMediaMimeType("video/x-m4v")); |
| 43 EXPECT_TRUE(IsStrictMediaMimeType("audio/mp4")); |
| 44 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-m4a")); |
| 45 |
| 46 EXPECT_TRUE(IsStrictMediaMimeType("application/x-mpegurl")); |
| 47 EXPECT_TRUE(IsStrictMediaMimeType("application/vnd.apple.mpegurl")); |
| 48 |
| 49 EXPECT_FALSE(IsStrictMediaMimeType("video/unknown")); |
| 50 EXPECT_FALSE(IsStrictMediaMimeType("Video/UNKNOWN")); |
| 51 EXPECT_FALSE(IsStrictMediaMimeType("audio/unknown")); |
| 52 EXPECT_FALSE(IsStrictMediaMimeType("application/unknown")); |
| 53 EXPECT_FALSE(IsStrictMediaMimeType("unknown/unknown")); |
| 54 } |
| 55 |
| 56 TEST(MimeUtilTest, CommonMediaMimeType) { |
| 57 #if defined(OS_ANDROID) |
| 58 bool HLSSupported; |
| 59 if (base::android::BuildInfo::GetInstance()->sdk_int() < 14) |
| 60 HLSSupported = false; |
| 61 else |
| 62 HLSSupported = true; |
| 63 #endif |
| 64 |
| 65 EXPECT_TRUE(IsSupportedMediaMimeType("audio/webm")); |
| 66 EXPECT_TRUE(IsSupportedMediaMimeType("video/webm")); |
| 67 |
| 68 EXPECT_TRUE(IsSupportedMediaMimeType("audio/wav")); |
| 69 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-wav")); |
| 70 |
| 71 EXPECT_TRUE(IsSupportedMediaMimeType("audio/ogg")); |
| 72 EXPECT_TRUE(IsSupportedMediaMimeType("application/ogg")); |
| 73 #if defined(OS_ANDROID) |
| 74 EXPECT_FALSE(IsSupportedMediaMimeType("video/ogg")); |
| 75 EXPECT_EQ(HLSSupported, IsSupportedMediaMimeType("application/x-mpegurl")); |
| 76 EXPECT_EQ(HLSSupported, |
| 77 IsSupportedMediaMimeType("application/vnd.apple.mpegurl")); |
| 78 #else |
| 79 EXPECT_TRUE(IsSupportedMediaMimeType("video/ogg")); |
| 80 EXPECT_FALSE(IsSupportedMediaMimeType("application/x-mpegurl")); |
| 81 EXPECT_FALSE(IsSupportedMediaMimeType("application/vnd.apple.mpegurl")); |
| 82 #endif // OS_ANDROID |
| 83 |
| 84 #if defined(USE_PROPRIETARY_CODECS) |
| 85 EXPECT_TRUE(IsSupportedMediaMimeType("audio/mp4")); |
| 86 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-m4a")); |
| 87 EXPECT_TRUE(IsSupportedMediaMimeType("video/mp4")); |
| 88 EXPECT_TRUE(IsSupportedMediaMimeType("video/x-m4v")); |
| 89 |
| 90 EXPECT_TRUE(IsSupportedMediaMimeType("audio/mp3")); |
| 91 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-mp3")); |
| 92 EXPECT_TRUE(IsSupportedMediaMimeType("audio/mpeg")); |
| 93 EXPECT_TRUE(IsSupportedMediaMimeType("audio/aac")); |
| 94 |
| 95 #if defined(ENABLE_MPEG2TS_STREAM_PARSER) |
| 96 EXPECT_TRUE(IsSupportedMediaMimeType("video/mp2t")); |
| 97 #else |
| 98 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp2t")); |
| 99 #endif |
| 100 #else |
| 101 EXPECT_FALSE(IsSupportedMediaMimeType("audio/mp4")); |
| 102 EXPECT_FALSE(IsSupportedMediaMimeType("audio/x-m4a")); |
| 103 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp4")); |
| 104 EXPECT_FALSE(IsSupportedMediaMimeType("video/x-m4v")); |
| 105 |
| 106 EXPECT_FALSE(IsSupportedMediaMimeType("audio/mp3")); |
| 107 EXPECT_FALSE(IsSupportedMediaMimeType("audio/x-mp3")); |
| 108 EXPECT_FALSE(IsSupportedMediaMimeType("audio/mpeg")); |
| 109 EXPECT_FALSE(IsSupportedMediaMimeType("audio/aac")); |
| 110 #endif // USE_PROPRIETARY_CODECS |
| 111 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp3")); |
| 112 |
| 113 EXPECT_FALSE(IsSupportedMediaMimeType("video/unknown")); |
| 114 EXPECT_FALSE(IsSupportedMediaMimeType("audio/unknown")); |
| 115 EXPECT_FALSE(IsSupportedMediaMimeType("unknown/unknown")); |
| 116 } |
| 117 |
| 118 // Note: codecs should only be a list of 2 or fewer; hence the restriction of |
| 119 // results' length to 2. |
| 120 TEST(MimeUtilTest, ParseCodecString) { |
| 121 const struct { |
| 122 const char* const original; |
| 123 size_t expected_size; |
| 124 const char* const results[2]; |
| 125 } tests[] = { |
| 126 { "\"bogus\"", 1, { "bogus" } }, |
| 127 { "0", 1, { "0" } }, |
| 128 { "avc1.42E01E, mp4a.40.2", 2, { "avc1", "mp4a" } }, |
| 129 { "\"mp4v.20.240, mp4a.40.2\"", 2, { "mp4v", "mp4a" } }, |
| 130 { "mp4v.20.8, samr", 2, { "mp4v", "samr" } }, |
| 131 { "\"theora, vorbis\"", 2, { "theora", "vorbis" } }, |
| 132 { "", 0, { } }, |
| 133 { "\"\"", 0, { } }, |
| 134 { "\" \"", 0, { } }, |
| 135 { ",", 2, { "", "" } }, |
| 136 }; |
| 137 |
| 138 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 139 std::vector<std::string> codecs_out; |
| 140 ParseCodecString(tests[i].original, &codecs_out, true); |
| 141 ASSERT_EQ(tests[i].expected_size, codecs_out.size()); |
| 142 for (size_t j = 0; j < tests[i].expected_size; ++j) |
| 143 EXPECT_EQ(tests[i].results[j], codecs_out[j]); |
| 144 } |
| 145 |
| 146 // Test without stripping the codec type. |
| 147 std::vector<std::string> codecs_out; |
| 148 ParseCodecString("avc1.42E01E, mp4a.40.2", &codecs_out, false); |
| 149 ASSERT_EQ(2u, codecs_out.size()); |
| 150 EXPECT_EQ("avc1.42E01E", codecs_out[0]); |
| 151 EXPECT_EQ("mp4a.40.2", codecs_out[1]); |
| 152 } |
| 153 |
| 154 } // namespace media |
OLD | NEW |