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
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "base/strings/string_split.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "net/base/mime_util.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 #if defined(OS_ANDROID)
12 #include "base/android/build_info.h"
17 TEST(MimeUtilTest
, ExtensionTest
) {
19 const base::FilePath::CharType
* extension
;
20 const char* const mime_type
;
23 {FILE_PATH_LITERAL("png"), "image/png", true},
24 {FILE_PATH_LITERAL("PNG"), "image/png", true},
25 {FILE_PATH_LITERAL("css"), "text/css", true},
26 {FILE_PATH_LITERAL("pjp"), "image/jpeg", true},
27 {FILE_PATH_LITERAL("pjpeg"), "image/jpeg", true},
28 #if defined(OS_ANDROID)
29 {FILE_PATH_LITERAL("m3u8"), "application/x-mpegurl", true},
31 {FILE_PATH_LITERAL("not an extension / for sure"), "", false},
34 std::string mime_type
;
37 for (size_t i
= 0; i
< arraysize(tests
); ++i
) {
38 rv
= GetMimeTypeFromExtension(tests
[i
].extension
, &mime_type
);
39 EXPECT_EQ(tests
[i
].valid
, rv
);
41 EXPECT_EQ(tests
[i
].mime_type
, mime_type
);
45 TEST(MimeUtilTest
, FileTest
) {
47 const base::FilePath::CharType
* file_path
;
48 const char* const mime_type
;
51 {FILE_PATH_LITERAL("c:\\foo\\bar.css"), "text/css", true},
52 {FILE_PATH_LITERAL("c:\\foo\\bar.CSS"), "text/css", true},
53 {FILE_PATH_LITERAL("c:\\blah"), "", false},
54 {FILE_PATH_LITERAL("/usr/local/bin/mplayer"), "", false},
55 {FILE_PATH_LITERAL("/home/foo/bar.css"), "text/css", true},
56 {FILE_PATH_LITERAL("/blah."), "", false},
57 {FILE_PATH_LITERAL("c:\\blah."), "", false},
60 std::string mime_type
;
63 for (size_t i
= 0; i
< arraysize(tests
); ++i
) {
64 rv
= GetMimeTypeFromFile(base::FilePath(tests
[i
].file_path
),
66 EXPECT_EQ(tests
[i
].valid
, rv
);
68 EXPECT_EQ(tests
[i
].mime_type
, mime_type
);
72 TEST(MimeUtilTest
, LookupTypes
) {
73 EXPECT_FALSE(IsUnsupportedTextMimeType("text/banana"));
74 EXPECT_TRUE(IsUnsupportedTextMimeType("text/vcard"));
76 EXPECT_TRUE(IsSupportedImageMimeType("image/jpeg"));
77 EXPECT_TRUE(IsSupportedImageMimeType("Image/JPEG"));
78 EXPECT_FALSE(IsSupportedImageMimeType("image/lolcat"));
79 EXPECT_FALSE(IsSupportedImageMimeType("Image/LolCat"));
80 EXPECT_TRUE(IsSupportedNonImageMimeType("text/html"));
81 EXPECT_TRUE(IsSupportedNonImageMimeType("text/css"));
82 EXPECT_TRUE(IsSupportedNonImageMimeType("text/"));
83 EXPECT_TRUE(IsSupportedNonImageMimeType("text/banana"));
84 EXPECT_TRUE(IsSupportedNonImageMimeType("Text/Banana"));
85 EXPECT_FALSE(IsSupportedNonImageMimeType("text/vcard"));
86 EXPECT_FALSE(IsSupportedNonImageMimeType("application/virus"));
87 EXPECT_FALSE(IsSupportedNonImageMimeType("Application/VIRUS"));
88 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-x509-user-cert"));
89 EXPECT_TRUE(IsSupportedNonImageMimeType("application/json"));
90 EXPECT_TRUE(IsSupportedNonImageMimeType("application/+json"));
91 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-suggestions+json"));
92 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-s+json;x=2"));
93 #if defined(OS_ANDROID)
94 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-x509-ca-cert"));
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"));
101 EXPECT_TRUE(IsSupportedMimeType("image/jpeg"));
102 EXPECT_FALSE(IsSupportedMimeType("image/lolcat"));
103 EXPECT_FALSE(IsSupportedMimeType("Image/LOLCAT"));
104 EXPECT_TRUE(IsSupportedMimeType("text/html"));
105 EXPECT_TRUE(IsSupportedMimeType("text/banana"));
106 EXPECT_TRUE(IsSupportedMimeType("Text/BANANA"));
107 EXPECT_FALSE(IsSupportedMimeType("text/vcard"));
108 EXPECT_FALSE(IsSupportedMimeType("application/virus"));
109 EXPECT_FALSE(IsSupportedMimeType("application/x-json"));
110 EXPECT_FALSE(IsSupportedMimeType("Application/X-JSON"));
111 EXPECT_FALSE(IsSupportedNonImageMimeType("application/vnd.doc;x=y+json"));
112 EXPECT_FALSE(IsSupportedNonImageMimeType("Application/VND.DOC;X=Y+JSON"));
115 TEST(MimeUtilTest
, StrictMediaMimeType
) {
116 EXPECT_TRUE(IsStrictMediaMimeType("video/webm"));
117 EXPECT_TRUE(IsStrictMediaMimeType("Video/WEBM"));
118 EXPECT_TRUE(IsStrictMediaMimeType("audio/webm"));
120 EXPECT_TRUE(IsStrictMediaMimeType("audio/wav"));
121 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-wav"));
123 EXPECT_TRUE(IsStrictMediaMimeType("video/ogg"));
124 EXPECT_TRUE(IsStrictMediaMimeType("audio/ogg"));
125 EXPECT_TRUE(IsStrictMediaMimeType("application/ogg"));
127 EXPECT_TRUE(IsStrictMediaMimeType("audio/mpeg"));
128 EXPECT_TRUE(IsStrictMediaMimeType("audio/mp3"));
129 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-mp3"));
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"));
136 EXPECT_TRUE(IsStrictMediaMimeType("application/x-mpegurl"));
137 EXPECT_TRUE(IsStrictMediaMimeType("application/vnd.apple.mpegurl"));
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"));
146 TEST(MimeUtilTest
, MatchesMimeType
) {
147 // MIME types are case insensitive.
148 EXPECT_TRUE(MatchesMimeType("VIDEO/*", "video/x-mpeg"));
149 EXPECT_TRUE(MatchesMimeType("video/*", "VIDEO/X-MPEG"));
151 EXPECT_TRUE(MatchesMimeType("*", "video/x-mpeg"));
152 EXPECT_TRUE(MatchesMimeType("video/*", "video/x-mpeg"));
153 EXPECT_TRUE(MatchesMimeType("video/*", "video/*"));
154 EXPECT_TRUE(MatchesMimeType("video/x-mpeg", "video/x-mpeg"));
155 EXPECT_TRUE(MatchesMimeType("application/*+xml",
156 "application/html+xml"));
157 EXPECT_TRUE(MatchesMimeType("application/*+xml", "application/+xml"));
158 EXPECT_TRUE(MatchesMimeType("application/*+json",
159 "application/x-myformat+json"));
160 EXPECT_TRUE(MatchesMimeType("aaa*aaa", "aaaaaa"));
161 EXPECT_TRUE(MatchesMimeType("*", std::string()));
162 EXPECT_FALSE(MatchesMimeType("video/", "video/x-mpeg"));
163 EXPECT_FALSE(MatchesMimeType("VIDEO/", "Video/X-MPEG"));
164 EXPECT_FALSE(MatchesMimeType(std::string(), "video/x-mpeg"));
165 EXPECT_FALSE(MatchesMimeType(std::string(), std::string()));
166 EXPECT_FALSE(MatchesMimeType("video/x-mpeg", std::string()));
167 EXPECT_FALSE(MatchesMimeType("application/*+xml", "application/xml"));
168 EXPECT_FALSE(MatchesMimeType("application/*+xml",
169 "application/html+xmlz"));
170 EXPECT_FALSE(MatchesMimeType("application/*+xml",
171 "applcation/html+xml"));
172 EXPECT_FALSE(MatchesMimeType("aaa*aaa", "aaaaa"));
174 EXPECT_TRUE(MatchesMimeType("*", "video/x-mpeg;param=val"));
175 EXPECT_TRUE(MatchesMimeType("*", "Video/X-MPEG;PARAM=VAL"));
176 EXPECT_TRUE(MatchesMimeType("video/*", "video/x-mpeg;param=val"));
177 EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/mpeg"));
178 EXPECT_FALSE(MatchesMimeType("Video/*;PARAM=VAL", "VIDEO/Mpeg"));
179 EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/mpeg;param=other"));
180 EXPECT_TRUE(MatchesMimeType("video/*;param=val", "video/mpeg;param=val"));
181 EXPECT_TRUE(MatchesMimeType("Video/*;PARAM=Val", "VIDEO/Mpeg;Param=Val"));
182 EXPECT_FALSE(MatchesMimeType("Video/*;PARAM=VAL", "VIDEO/Mpeg;Param=Val"));
183 EXPECT_TRUE(MatchesMimeType("video/x-mpeg", "video/x-mpeg;param=val"));
184 EXPECT_TRUE(MatchesMimeType("video/x-mpeg;param=val",
185 "video/x-mpeg;param=val"));
186 EXPECT_FALSE(MatchesMimeType("video/x-mpeg;param2=val2",
187 "video/x-mpeg;param=val"));
188 EXPECT_FALSE(MatchesMimeType("video/x-mpeg;param2=val2",
189 "video/x-mpeg;param2=val"));
190 EXPECT_TRUE(MatchesMimeType("video/x-mpeg;param=val",
191 "video/x-mpeg;param=val;param2=val2"));
192 EXPECT_TRUE(MatchesMimeType("Video/X-Mpeg;Param=Val",
193 "VIDEO/X-MPEG;PARAM=Val;PARAM2=val2"));
194 EXPECT_TRUE(MatchesMimeType("Video/X-Mpeg;Param=VAL",
195 "VIDEO/X-MPEG;PARAM=VAL;PARAM2=val2"));
196 EXPECT_FALSE(MatchesMimeType("Video/X-Mpeg;Param=val",
197 "VIDEO/X-MPEG;PARAM=VAL;PARAM2=val2"));
198 EXPECT_FALSE(MatchesMimeType("video/x-mpeg;param=VAL;param2=val2",
199 "video/x-mpeg;param=val;param2=val2"));
200 EXPECT_TRUE(MatchesMimeType("video/x-mpeg;param2=val2;param=val",
201 "video/x-mpeg;param=val;param2=val2"));
202 EXPECT_FALSE(MatchesMimeType("video/x-mpeg;param3=val3;param=val",
203 "video/x-mpeg;param=val;param2=val2"));
204 EXPECT_TRUE(MatchesMimeType("video/x-mpeg;param=val ;param2=val2 ",
205 "video/x-mpeg;param=val;param2=val2"));
207 EXPECT_TRUE(MatchesMimeType("*/*;param=val", "video/x-mpeg;param=val"));
208 EXPECT_FALSE(MatchesMimeType("*/*;param=val", "video/x-mpeg;param=val2"));
210 EXPECT_TRUE(MatchesMimeType("*", "*"));
211 EXPECT_TRUE(MatchesMimeType("*", "*/*"));
212 EXPECT_TRUE(MatchesMimeType("*/*", "*/*"));
213 EXPECT_TRUE(MatchesMimeType("*/*", "*"));
214 EXPECT_TRUE(MatchesMimeType("video/*", "video/*"));
215 EXPECT_FALSE(MatchesMimeType("video/*", "*/*"));
216 EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/*"));
217 EXPECT_TRUE(MatchesMimeType("video/*;param=val", "video/*;param=val"));
218 EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/*;param=val2"));
220 EXPECT_TRUE(MatchesMimeType("ab*cd", "abxxxcd"));
221 EXPECT_TRUE(MatchesMimeType("ab*cd", "abx/xcd"));
222 EXPECT_TRUE(MatchesMimeType("ab/*cd", "ab/xxxcd"));
225 TEST(MimeUtilTest
, CommonMediaMimeType
) {
226 #if defined(OS_ANDROID)
228 if (base::android::BuildInfo::GetInstance()->sdk_int() < 14)
229 HLSSupported
= false;
234 EXPECT_TRUE(IsSupportedMediaMimeType("audio/webm"));
235 EXPECT_TRUE(IsSupportedMediaMimeType("video/webm"));
237 EXPECT_TRUE(IsSupportedMediaMimeType("audio/wav"));
238 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-wav"));
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"));
248 EXPECT_TRUE(IsSupportedMediaMimeType("video/ogg"));
249 EXPECT_FALSE(IsSupportedMediaMimeType("application/x-mpegurl"));
250 EXPECT_FALSE(IsSupportedMediaMimeType("application/vnd.apple.mpegurl"));
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"));
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"));
264 #if defined(ENABLE_MPEG2TS_STREAM_PARSER)
265 EXPECT_TRUE(IsSupportedMediaMimeType("video/mp2t"));
267 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp2t"));
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"));
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"));
282 EXPECT_FALSE(IsSupportedMediaMimeType("video/unknown"));
283 EXPECT_FALSE(IsSupportedMediaMimeType("audio/unknown"));
284 EXPECT_FALSE(IsSupportedMediaMimeType("unknown/unknown"));
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
) {
291 const char* const original
;
292 size_t expected_size
;
293 const char* const results
[2];
295 { "\"bogus\"", 1, { "bogus" } },
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" } },
304 { ",", 2, { "", "" } },
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
]);
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]);
323 TEST(MimeUtilTest
, TestParseMimeTypeWithoutParameter
) {
324 std::string
nonAscii("application/nonutf8");
325 EXPECT_TRUE(ParseMimeTypeWithoutParameter(nonAscii
, NULL
, NULL
));
327 nonAscii
.append(base::WideToUTF8(L
"\u2603"));
329 nonAscii
.append("\u2603"); // unicode snowman
331 EXPECT_FALSE(ParseMimeTypeWithoutParameter(nonAscii
, NULL
, NULL
));
333 std::string top_level_type
;
335 EXPECT_TRUE(ParseMimeTypeWithoutParameter(
336 "application/mime", &top_level_type
, &subtype
));
337 EXPECT_EQ("application", top_level_type
);
338 EXPECT_EQ("mime", subtype
);
340 // Various allowed subtype forms.
341 EXPECT_TRUE(ParseMimeTypeWithoutParameter("application/json", NULL
, NULL
));
342 EXPECT_TRUE(ParseMimeTypeWithoutParameter(
343 "application/x-suggestions+json", NULL
, NULL
));
344 EXPECT_TRUE(ParseMimeTypeWithoutParameter("application/+json", NULL
, NULL
));
346 // Upper case letters are allowed.
347 EXPECT_TRUE(ParseMimeTypeWithoutParameter("text/mime", NULL
, NULL
));
348 EXPECT_TRUE(ParseMimeTypeWithoutParameter("TEXT/mime", NULL
, NULL
));
349 EXPECT_TRUE(ParseMimeTypeWithoutParameter("Text/mime", NULL
, NULL
));
350 EXPECT_TRUE(ParseMimeTypeWithoutParameter("TeXt/mime", NULL
, NULL
));
352 // Experimental types are also considered to be valid.
353 EXPECT_TRUE(ParseMimeTypeWithoutParameter("x-video/mime", NULL
, NULL
));
354 EXPECT_TRUE(ParseMimeTypeWithoutParameter("X-Video/mime", NULL
, NULL
));
356 EXPECT_FALSE(ParseMimeTypeWithoutParameter("text", NULL
, NULL
));
357 EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/", NULL
, NULL
));
358 EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/ ", NULL
, NULL
));
359 EXPECT_FALSE(ParseMimeTypeWithoutParameter("te(xt/ ", NULL
, NULL
));
360 EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/()plain", NULL
, NULL
));
362 EXPECT_FALSE(ParseMimeTypeWithoutParameter("x-video", NULL
, NULL
));
363 EXPECT_FALSE(ParseMimeTypeWithoutParameter("x-video/", NULL
, NULL
));
365 EXPECT_FALSE(ParseMimeTypeWithoutParameter("application/a/b/c", NULL
, NULL
));
367 //EXPECT_TRUE(ParseMimeTypeWithoutParameter("video/mime;parameter"));
370 TEST(MimeUtilTest
, TestIsValidTopLevelMimeType
) {
371 EXPECT_TRUE(IsValidTopLevelMimeType("application"));
372 EXPECT_TRUE(IsValidTopLevelMimeType("audio"));
373 EXPECT_TRUE(IsValidTopLevelMimeType("example"));
374 EXPECT_TRUE(IsValidTopLevelMimeType("image"));
375 EXPECT_TRUE(IsValidTopLevelMimeType("message"));
376 EXPECT_TRUE(IsValidTopLevelMimeType("model"));
377 EXPECT_TRUE(IsValidTopLevelMimeType("multipart"));
378 EXPECT_TRUE(IsValidTopLevelMimeType("text"));
379 EXPECT_TRUE(IsValidTopLevelMimeType("video"));
381 EXPECT_TRUE(IsValidTopLevelMimeType("TEXT"));
382 EXPECT_TRUE(IsValidTopLevelMimeType("Text"));
383 EXPECT_TRUE(IsValidTopLevelMimeType("TeXt"));
385 EXPECT_FALSE(IsValidTopLevelMimeType("mime"));
386 EXPECT_FALSE(IsValidTopLevelMimeType(""));
387 EXPECT_FALSE(IsValidTopLevelMimeType("/"));
388 EXPECT_FALSE(IsValidTopLevelMimeType(" "));
390 EXPECT_TRUE(IsValidTopLevelMimeType("x-video"));
391 EXPECT_TRUE(IsValidTopLevelMimeType("X-video"));
393 EXPECT_FALSE(IsValidTopLevelMimeType("x-"));
396 TEST(MimeUtilTest
, TestGetExtensionsForMimeType
) {
398 const char* const mime_type
;
399 size_t min_expected_size
;
400 const char* const contained_result
;
402 { "text/plain", 2, "txt" },
404 { "message/*", 1, "eml" },
405 { "MeSsAge/*", 1, "eml" },
406 { "image/bmp", 1, "bmp" },
407 { "video/*", 6, "mp4" },
408 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_IOS)
409 { "video/*", 6, "mpg" },
411 { "video/*", 6, "mpeg" },
413 { "audio/*", 6, "oga" },
414 { "aUDIo/*", 6, "wav" },
417 for (size_t i
= 0; i
< arraysize(tests
); ++i
) {
418 std::vector
<base::FilePath::StringType
> extensions
;
419 GetExtensionsForMimeType(tests
[i
].mime_type
, &extensions
);
420 ASSERT_TRUE(tests
[i
].min_expected_size
<= extensions
.size());
422 if (!tests
[i
].contained_result
)
426 for (size_t j
= 0; !found
&& j
< extensions
.size(); ++j
) {
428 if (extensions
[j
] == base::UTF8ToWide(tests
[i
].contained_result
))
431 if (extensions
[j
] == tests
[i
].contained_result
)
435 ASSERT_TRUE(found
) << "Must find at least the contained result within "
436 << tests
[i
].mime_type
;
440 TEST(MimeUtilTest
, TestGetCertificateMimeTypeForMimeType
) {
441 EXPECT_EQ(CERTIFICATE_MIME_TYPE_X509_USER_CERT
,
442 GetCertificateMimeTypeForMimeType("application/x-x509-user-cert"));
443 EXPECT_EQ(CERTIFICATE_MIME_TYPE_X509_USER_CERT
,
444 GetCertificateMimeTypeForMimeType("Application/X-X509-USER-CERT"));
445 #if defined(OS_ANDROID)
446 // Only Android supports CA Certs and PKCS12 archives.
447 EXPECT_EQ(CERTIFICATE_MIME_TYPE_X509_CA_CERT
,
448 GetCertificateMimeTypeForMimeType("application/x-x509-ca-cert"));
449 EXPECT_EQ(CERTIFICATE_MIME_TYPE_PKCS12_ARCHIVE
,
450 GetCertificateMimeTypeForMimeType("application/x-pkcs12"));
452 EXPECT_EQ(CERTIFICATE_MIME_TYPE_UNKNOWN
,
453 GetCertificateMimeTypeForMimeType("application/x-x509-ca-cert"));
454 EXPECT_EQ(CERTIFICATE_MIME_TYPE_UNKNOWN
,
455 GetCertificateMimeTypeForMimeType("application/x-pkcs12"));
457 EXPECT_EQ(CERTIFICATE_MIME_TYPE_UNKNOWN
,
458 GetCertificateMimeTypeForMimeType("text/plain"));
461 TEST(MimeUtilTest
, TestAddMultipartValueForUpload
) {
462 const char ref_output
[] =
463 "--boundary\r\nContent-Disposition: form-data;"
464 " name=\"value name\"\r\nContent-Type: content type"
466 "--boundary\r\nContent-Disposition: form-data;"
467 " name=\"value name\"\r\n\r\nvalue\r\n"
469 std::string post_data
;
470 AddMultipartValueForUpload("value name", "value", "boundary",
471 "content type", &post_data
);
472 AddMultipartValueForUpload("value name", "value", "boundary",
474 AddMultipartFinalDelimiterForUpload("boundary", &post_data
);
475 EXPECT_STREQ(ref_output
, post_data
.c_str());