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