OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/strings/string_split.h" | 6 #include "base/strings/string_split.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "net/base/mime_util.h" | 8 #include "net/base/mime_util.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 EXPECT_FALSE(IsSupportedNonImageMimeType("application/virus")); | 86 EXPECT_FALSE(IsSupportedNonImageMimeType("application/virus")); |
87 EXPECT_FALSE(IsSupportedNonImageMimeType("Application/VIRUS")); | 87 EXPECT_FALSE(IsSupportedNonImageMimeType("Application/VIRUS")); |
88 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-x509-user-cert")); | 88 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-x509-user-cert")); |
89 EXPECT_TRUE(IsSupportedNonImageMimeType("application/json")); | 89 EXPECT_TRUE(IsSupportedNonImageMimeType("application/json")); |
90 EXPECT_TRUE(IsSupportedNonImageMimeType("application/+json")); | 90 EXPECT_TRUE(IsSupportedNonImageMimeType("application/+json")); |
91 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-suggestions+json")); | 91 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-suggestions+json")); |
92 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-s+json;x=2")); | 92 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-s+json;x=2")); |
93 #if defined(OS_ANDROID) | 93 #if defined(OS_ANDROID) |
94 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-x509-ca-cert")); | 94 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-x509-ca-cert")); |
95 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-pkcs12")); | 95 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-pkcs12")); |
96 EXPECT_TRUE(IsSupportedMediaMimeType("application/vnd.apple.mpegurl")); | |
97 EXPECT_TRUE(IsSupportedMediaMimeType("application/x-mpegurl")); | |
98 EXPECT_TRUE(IsSupportedMediaMimeType("Application/X-MPEGURL")); | |
99 #endif | 96 #endif |
100 | 97 |
101 EXPECT_TRUE(IsSupportedMimeType("image/jpeg")); | 98 EXPECT_TRUE(IsSupportedMimeType("image/jpeg")); |
102 EXPECT_FALSE(IsSupportedMimeType("image/lolcat")); | 99 EXPECT_FALSE(IsSupportedMimeType("image/lolcat")); |
103 EXPECT_FALSE(IsSupportedMimeType("Image/LOLCAT")); | 100 EXPECT_FALSE(IsSupportedMimeType("Image/LOLCAT")); |
104 EXPECT_TRUE(IsSupportedMimeType("text/html")); | 101 EXPECT_TRUE(IsSupportedMimeType("text/html")); |
105 EXPECT_TRUE(IsSupportedMimeType("text/banana")); | 102 EXPECT_TRUE(IsSupportedMimeType("text/banana")); |
106 EXPECT_TRUE(IsSupportedMimeType("Text/BANANA")); | 103 EXPECT_TRUE(IsSupportedMimeType("Text/BANANA")); |
107 EXPECT_FALSE(IsSupportedMimeType("text/vcard")); | 104 EXPECT_FALSE(IsSupportedMimeType("text/vcard")); |
108 EXPECT_FALSE(IsSupportedMimeType("application/virus")); | 105 EXPECT_FALSE(IsSupportedMimeType("application/virus")); |
109 EXPECT_FALSE(IsSupportedMimeType("application/x-json")); | 106 EXPECT_FALSE(IsSupportedMimeType("application/x-json")); |
110 EXPECT_FALSE(IsSupportedMimeType("Application/X-JSON")); | 107 EXPECT_FALSE(IsSupportedMimeType("Application/X-JSON")); |
111 EXPECT_FALSE(IsSupportedNonImageMimeType("application/vnd.doc;x=y+json")); | 108 EXPECT_FALSE(IsSupportedNonImageMimeType("application/vnd.doc;x=y+json")); |
112 EXPECT_FALSE(IsSupportedNonImageMimeType("Application/VND.DOC;X=Y+JSON")); | 109 EXPECT_FALSE(IsSupportedNonImageMimeType("Application/VND.DOC;X=Y+JSON")); |
113 } | 110 } |
114 | 111 |
115 TEST(MimeUtilTest, StrictMediaMimeType) { | |
116 EXPECT_TRUE(IsStrictMediaMimeType("video/webm")); | |
117 EXPECT_TRUE(IsStrictMediaMimeType("Video/WEBM")); | |
118 EXPECT_TRUE(IsStrictMediaMimeType("audio/webm")); | |
119 | |
120 EXPECT_TRUE(IsStrictMediaMimeType("audio/wav")); | |
121 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-wav")); | |
122 | |
123 EXPECT_TRUE(IsStrictMediaMimeType("video/ogg")); | |
124 EXPECT_TRUE(IsStrictMediaMimeType("audio/ogg")); | |
125 EXPECT_TRUE(IsStrictMediaMimeType("application/ogg")); | |
126 | |
127 EXPECT_TRUE(IsStrictMediaMimeType("audio/mpeg")); | |
128 EXPECT_TRUE(IsStrictMediaMimeType("audio/mp3")); | |
129 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-mp3")); | |
130 | |
131 EXPECT_TRUE(IsStrictMediaMimeType("video/mp4")); | |
132 EXPECT_TRUE(IsStrictMediaMimeType("video/x-m4v")); | |
133 EXPECT_TRUE(IsStrictMediaMimeType("audio/mp4")); | |
134 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-m4a")); | |
135 | |
136 EXPECT_TRUE(IsStrictMediaMimeType("application/x-mpegurl")); | |
137 EXPECT_TRUE(IsStrictMediaMimeType("application/vnd.apple.mpegurl")); | |
138 | |
139 EXPECT_FALSE(IsStrictMediaMimeType("video/unknown")); | |
140 EXPECT_FALSE(IsStrictMediaMimeType("Video/UNKNOWN")); | |
141 EXPECT_FALSE(IsStrictMediaMimeType("audio/unknown")); | |
142 EXPECT_FALSE(IsStrictMediaMimeType("application/unknown")); | |
143 EXPECT_FALSE(IsStrictMediaMimeType("unknown/unknown")); | |
144 } | |
145 | |
146 TEST(MimeUtilTest, MatchesMimeType) { | 112 TEST(MimeUtilTest, MatchesMimeType) { |
147 // MIME types are case insensitive. | 113 // MIME types are case insensitive. |
148 EXPECT_TRUE(MatchesMimeType("VIDEO/*", "video/x-mpeg")); | 114 EXPECT_TRUE(MatchesMimeType("VIDEO/*", "video/x-mpeg")); |
149 EXPECT_TRUE(MatchesMimeType("video/*", "VIDEO/X-MPEG")); | 115 EXPECT_TRUE(MatchesMimeType("video/*", "VIDEO/X-MPEG")); |
150 | 116 |
151 EXPECT_TRUE(MatchesMimeType("*", "video/x-mpeg")); | 117 EXPECT_TRUE(MatchesMimeType("*", "video/x-mpeg")); |
152 EXPECT_TRUE(MatchesMimeType("video/*", "video/x-mpeg")); | 118 EXPECT_TRUE(MatchesMimeType("video/*", "video/x-mpeg")); |
153 EXPECT_TRUE(MatchesMimeType("video/*", "video/*")); | 119 EXPECT_TRUE(MatchesMimeType("video/*", "video/*")); |
154 EXPECT_TRUE(MatchesMimeType("video/x-mpeg", "video/x-mpeg")); | 120 EXPECT_TRUE(MatchesMimeType("video/x-mpeg", "video/x-mpeg")); |
155 EXPECT_TRUE(MatchesMimeType("application/*+xml", | 121 EXPECT_TRUE(MatchesMimeType("application/*+xml", |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 EXPECT_FALSE(MatchesMimeType("video/*", "*/*")); | 181 EXPECT_FALSE(MatchesMimeType("video/*", "*/*")); |
216 EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/*")); | 182 EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/*")); |
217 EXPECT_TRUE(MatchesMimeType("video/*;param=val", "video/*;param=val")); | 183 EXPECT_TRUE(MatchesMimeType("video/*;param=val", "video/*;param=val")); |
218 EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/*;param=val2")); | 184 EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/*;param=val2")); |
219 | 185 |
220 EXPECT_TRUE(MatchesMimeType("ab*cd", "abxxxcd")); | 186 EXPECT_TRUE(MatchesMimeType("ab*cd", "abxxxcd")); |
221 EXPECT_TRUE(MatchesMimeType("ab*cd", "abx/xcd")); | 187 EXPECT_TRUE(MatchesMimeType("ab*cd", "abx/xcd")); |
222 EXPECT_TRUE(MatchesMimeType("ab/*cd", "ab/xxxcd")); | 188 EXPECT_TRUE(MatchesMimeType("ab/*cd", "ab/xxxcd")); |
223 } | 189 } |
224 | 190 |
225 TEST(MimeUtilTest, CommonMediaMimeType) { | |
226 #if defined(OS_ANDROID) | |
227 bool HLSSupported; | |
228 if (base::android::BuildInfo::GetInstance()->sdk_int() < 14) | |
229 HLSSupported = false; | |
230 else | |
231 HLSSupported = true; | |
232 #endif | |
233 | |
234 EXPECT_TRUE(IsSupportedMediaMimeType("audio/webm")); | |
235 EXPECT_TRUE(IsSupportedMediaMimeType("video/webm")); | |
236 | |
237 EXPECT_TRUE(IsSupportedMediaMimeType("audio/wav")); | |
238 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-wav")); | |
239 | |
240 EXPECT_TRUE(IsSupportedMediaMimeType("audio/ogg")); | |
241 EXPECT_TRUE(IsSupportedMediaMimeType("application/ogg")); | |
242 #if defined(OS_ANDROID) | |
243 EXPECT_FALSE(IsSupportedMediaMimeType("video/ogg")); | |
244 EXPECT_EQ(HLSSupported, IsSupportedMediaMimeType("application/x-mpegurl")); | |
245 EXPECT_EQ(HLSSupported, | |
246 IsSupportedMediaMimeType("application/vnd.apple.mpegurl")); | |
247 #else | |
248 EXPECT_TRUE(IsSupportedMediaMimeType("video/ogg")); | |
249 EXPECT_FALSE(IsSupportedMediaMimeType("application/x-mpegurl")); | |
250 EXPECT_FALSE(IsSupportedMediaMimeType("application/vnd.apple.mpegurl")); | |
251 #endif // OS_ANDROID | |
252 | |
253 #if defined(USE_PROPRIETARY_CODECS) | |
254 EXPECT_TRUE(IsSupportedMediaMimeType("audio/mp4")); | |
255 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-m4a")); | |
256 EXPECT_TRUE(IsSupportedMediaMimeType("video/mp4")); | |
257 EXPECT_TRUE(IsSupportedMediaMimeType("video/x-m4v")); | |
258 | |
259 EXPECT_TRUE(IsSupportedMediaMimeType("audio/mp3")); | |
260 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-mp3")); | |
261 EXPECT_TRUE(IsSupportedMediaMimeType("audio/mpeg")); | |
262 EXPECT_TRUE(IsSupportedMediaMimeType("audio/aac")); | |
263 | |
264 #if defined(ENABLE_MPEG2TS_STREAM_PARSER) | |
265 EXPECT_TRUE(IsSupportedMediaMimeType("video/mp2t")); | |
266 #else | |
267 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp2t")); | |
268 #endif | |
269 #else | |
270 EXPECT_FALSE(IsSupportedMediaMimeType("audio/mp4")); | |
271 EXPECT_FALSE(IsSupportedMediaMimeType("audio/x-m4a")); | |
272 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp4")); | |
273 EXPECT_FALSE(IsSupportedMediaMimeType("video/x-m4v")); | |
274 | |
275 EXPECT_FALSE(IsSupportedMediaMimeType("audio/mp3")); | |
276 EXPECT_FALSE(IsSupportedMediaMimeType("audio/x-mp3")); | |
277 EXPECT_FALSE(IsSupportedMediaMimeType("audio/mpeg")); | |
278 EXPECT_FALSE(IsSupportedMediaMimeType("audio/aac")); | |
279 #endif // USE_PROPRIETARY_CODECS | |
280 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp3")); | |
281 | |
282 EXPECT_FALSE(IsSupportedMediaMimeType("video/unknown")); | |
283 EXPECT_FALSE(IsSupportedMediaMimeType("audio/unknown")); | |
284 EXPECT_FALSE(IsSupportedMediaMimeType("unknown/unknown")); | |
285 } | |
286 | |
287 // Note: codecs should only be a list of 2 or fewer; hence the restriction of | |
288 // results' length to 2. | |
289 TEST(MimeUtilTest, ParseCodecString) { | |
290 const struct { | |
291 const char* const original; | |
292 size_t expected_size; | |
293 const char* const results[2]; | |
294 } tests[] = { | |
295 { "\"bogus\"", 1, { "bogus" } }, | |
296 { "0", 1, { "0" } }, | |
297 { "avc1.42E01E, mp4a.40.2", 2, { "avc1", "mp4a" } }, | |
298 { "\"mp4v.20.240, mp4a.40.2\"", 2, { "mp4v", "mp4a" } }, | |
299 { "mp4v.20.8, samr", 2, { "mp4v", "samr" } }, | |
300 { "\"theora, vorbis\"", 2, { "theora", "vorbis" } }, | |
301 { "", 0, { } }, | |
302 { "\"\"", 0, { } }, | |
303 { "\" \"", 0, { } }, | |
304 { ",", 2, { "", "" } }, | |
305 }; | |
306 | |
307 for (size_t i = 0; i < arraysize(tests); ++i) { | |
308 std::vector<std::string> codecs_out; | |
309 ParseCodecString(tests[i].original, &codecs_out, true); | |
310 ASSERT_EQ(tests[i].expected_size, codecs_out.size()); | |
311 for (size_t j = 0; j < tests[i].expected_size; ++j) | |
312 EXPECT_EQ(tests[i].results[j], codecs_out[j]); | |
313 } | |
314 | |
315 // Test without stripping the codec type. | |
316 std::vector<std::string> codecs_out; | |
317 ParseCodecString("avc1.42E01E, mp4a.40.2", &codecs_out, false); | |
318 ASSERT_EQ(2u, codecs_out.size()); | |
319 EXPECT_EQ("avc1.42E01E", codecs_out[0]); | |
320 EXPECT_EQ("mp4a.40.2", codecs_out[1]); | |
321 } | |
322 | |
323 TEST(MimeUtilTest, TestParseMimeTypeWithoutParameter) { | 191 TEST(MimeUtilTest, TestParseMimeTypeWithoutParameter) { |
324 std::string nonAscii("application/nonutf8"); | 192 std::string nonAscii("application/nonutf8"); |
325 EXPECT_TRUE(ParseMimeTypeWithoutParameter(nonAscii, NULL, NULL)); | 193 EXPECT_TRUE(ParseMimeTypeWithoutParameter(nonAscii, NULL, NULL)); |
326 #if defined(OS_WIN) | 194 #if defined(OS_WIN) |
327 nonAscii.append(base::WideToUTF8(L"\u2603")); | 195 nonAscii.append(base::WideToUTF8(L"\u2603")); |
328 #else | 196 #else |
329 nonAscii.append("\u2603"); // unicode snowman | 197 nonAscii.append("\u2603"); // unicode snowman |
330 #endif | 198 #endif |
331 EXPECT_FALSE(ParseMimeTypeWithoutParameter(nonAscii, NULL, NULL)); | 199 EXPECT_FALSE(ParseMimeTypeWithoutParameter(nonAscii, NULL, NULL)); |
332 | 200 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 std::string post_data; | 337 std::string post_data; |
470 AddMultipartValueForUpload("value name", "value", "boundary", | 338 AddMultipartValueForUpload("value name", "value", "boundary", |
471 "content type", &post_data); | 339 "content type", &post_data); |
472 AddMultipartValueForUpload("value name", "value", "boundary", | 340 AddMultipartValueForUpload("value name", "value", "boundary", |
473 "", &post_data); | 341 "", &post_data); |
474 AddMultipartFinalDelimiterForUpload("boundary", &post_data); | 342 AddMultipartFinalDelimiterForUpload("boundary", &post_data); |
475 EXPECT_STREQ(ref_output, post_data.c_str()); | 343 EXPECT_STREQ(ref_output, post_data.c_str()); |
476 } | 344 } |
477 | 345 |
478 } // namespace net | 346 } // namespace net |
OLD | NEW |