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.
5 #include "base/basictypes.h"
6 #include "base/strings/string_split.h"
7 #include "build/build_config.h"
8 #include "media/base/mime_util.h"
9 #include "testing/gtest/include/gtest/gtest.h"
13 TEST(MimeUtilTest
, StrictMediaMimeType
) {
14 EXPECT_TRUE(IsStrictMediaMimeType("video/webm"));
15 EXPECT_TRUE(IsStrictMediaMimeType("Video/WEBM"));
16 EXPECT_TRUE(IsStrictMediaMimeType("audio/webm"));
18 EXPECT_TRUE(IsStrictMediaMimeType("audio/wav"));
19 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-wav"));
21 EXPECT_TRUE(IsStrictMediaMimeType("video/ogg"));
22 EXPECT_TRUE(IsStrictMediaMimeType("audio/ogg"));
23 EXPECT_TRUE(IsStrictMediaMimeType("application/ogg"));
25 EXPECT_TRUE(IsStrictMediaMimeType("audio/mpeg"));
26 EXPECT_TRUE(IsStrictMediaMimeType("audio/mp3"));
27 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-mp3"));
29 EXPECT_TRUE(IsStrictMediaMimeType("video/mp4"));
30 EXPECT_TRUE(IsStrictMediaMimeType("video/x-m4v"));
31 EXPECT_TRUE(IsStrictMediaMimeType("audio/mp4"));
32 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-m4a"));
34 EXPECT_TRUE(IsStrictMediaMimeType("application/x-mpegurl"));
35 EXPECT_TRUE(IsStrictMediaMimeType("application/vnd.apple.mpegurl"));
37 EXPECT_FALSE(IsStrictMediaMimeType("video/unknown"));
38 EXPECT_FALSE(IsStrictMediaMimeType("Video/UNKNOWN"));
39 EXPECT_FALSE(IsStrictMediaMimeType("audio/unknown"));
40 EXPECT_FALSE(IsStrictMediaMimeType("application/unknown"));
41 EXPECT_FALSE(IsStrictMediaMimeType("unknown/unknown"));
44 TEST(MimeUtilTest
, CommonMediaMimeType
) {
45 EXPECT_TRUE(IsSupportedMediaMimeType("audio/webm"));
46 EXPECT_TRUE(IsSupportedMediaMimeType("video/webm"));
48 EXPECT_TRUE(IsSupportedMediaMimeType("audio/wav"));
49 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-wav"));
51 EXPECT_TRUE(IsSupportedMediaMimeType("audio/ogg"));
52 EXPECT_TRUE(IsSupportedMediaMimeType("application/ogg"));
53 #if defined(OS_ANDROID)
54 EXPECT_FALSE(IsSupportedMediaMimeType("video/ogg"));
56 EXPECT_TRUE(IsSupportedMediaMimeType("video/ogg"));
59 #if defined(OS_ANDROID)
60 // HLS is supported on Android API level 14 and higher and Chrome supports
61 // API levels 15 and higher, so these are expected to be supported.
62 bool kHlsSupported
= true;
64 bool kHlsSupported
= false;
67 EXPECT_EQ(kHlsSupported
, IsSupportedMediaMimeType("application/x-mpegurl"));
68 EXPECT_EQ(kHlsSupported
, IsSupportedMediaMimeType("Application/X-MPEGURL"));
69 EXPECT_EQ(kHlsSupported
, IsSupportedMediaMimeType(
70 "application/vnd.apple.mpegurl"));
72 #if defined(USE_PROPRIETARY_CODECS)
73 EXPECT_TRUE(IsSupportedMediaMimeType("audio/mp4"));
74 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-m4a"));
75 EXPECT_TRUE(IsSupportedMediaMimeType("video/mp4"));
76 EXPECT_TRUE(IsSupportedMediaMimeType("video/x-m4v"));
78 EXPECT_TRUE(IsSupportedMediaMimeType("audio/mp3"));
79 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-mp3"));
80 EXPECT_TRUE(IsSupportedMediaMimeType("audio/mpeg"));
81 EXPECT_TRUE(IsSupportedMediaMimeType("audio/aac"));
83 #if defined(ENABLE_MPEG2TS_STREAM_PARSER)
84 EXPECT_TRUE(IsSupportedMediaMimeType("video/mp2t"));
86 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp2t"));
89 EXPECT_FALSE(IsSupportedMediaMimeType("audio/mp4"));
90 EXPECT_FALSE(IsSupportedMediaMimeType("audio/x-m4a"));
91 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp4"));
92 EXPECT_FALSE(IsSupportedMediaMimeType("video/x-m4v"));
94 EXPECT_FALSE(IsSupportedMediaMimeType("audio/mp3"));
95 EXPECT_FALSE(IsSupportedMediaMimeType("audio/x-mp3"));
96 EXPECT_FALSE(IsSupportedMediaMimeType("audio/mpeg"));
97 EXPECT_FALSE(IsSupportedMediaMimeType("audio/aac"));
98 #endif // USE_PROPRIETARY_CODECS
99 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp3"));
101 EXPECT_FALSE(IsSupportedMediaMimeType("video/unknown"));
102 EXPECT_FALSE(IsSupportedMediaMimeType("audio/unknown"));
103 EXPECT_FALSE(IsSupportedMediaMimeType("unknown/unknown"));
106 // Note: codecs should only be a list of 2 or fewer; hence the restriction of
107 // results' length to 2.
108 TEST(MimeUtilTest
, ParseCodecString
) {
110 const char* const original
;
111 size_t expected_size
;
112 const char* const results
[2];
114 { "\"bogus\"", 1, { "bogus" } },
116 { "avc1.42E01E, mp4a.40.2", 2, { "avc1", "mp4a" } },
117 { "\"mp4v.20.240, mp4a.40.2\"", 2, { "mp4v", "mp4a" } },
118 { "mp4v.20.8, samr", 2, { "mp4v", "samr" } },
119 { "\"theora, vorbis\"", 2, { "theora", "vorbis" } },
123 { ",", 2, { "", "" } },
126 for (size_t i
= 0; i
< arraysize(tests
); ++i
) {
127 std::vector
<std::string
> codecs_out
;
128 ParseCodecString(tests
[i
].original
, &codecs_out
, true);
129 ASSERT_EQ(tests
[i
].expected_size
, codecs_out
.size());
130 for (size_t j
= 0; j
< tests
[i
].expected_size
; ++j
)
131 EXPECT_EQ(tests
[i
].results
[j
], codecs_out
[j
]);
134 // Test without stripping the codec type.
135 std::vector
<std::string
> codecs_out
;
136 ParseCodecString("avc1.42E01E, mp4a.40.2", &codecs_out
, false);
137 ASSERT_EQ(2u, codecs_out
.size());
138 EXPECT_EQ("avc1.42E01E", codecs_out
[0]);
139 EXPECT_EQ("mp4a.40.2", codecs_out
[1]);