Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / base / mime_util_unittest.cc
blob08a3dfd9321843525111a05ed4a762a968ef1a04
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"
13 #endif
15 namespace net {
17 TEST(MimeUtilTest, ExtensionTest) {
18 const struct {
19 const base::FilePath::CharType* extension;
20 const char* mime_type;
21 bool valid;
22 } tests[] = {
23 { FILE_PATH_LITERAL("png"), "image/png", true },
24 { FILE_PATH_LITERAL("css"), "text/css", true },
25 { FILE_PATH_LITERAL("pjp"), "image/jpeg", true },
26 { FILE_PATH_LITERAL("pjpeg"), "image/jpeg", true },
27 #if defined(OS_ANDROID)
28 { FILE_PATH_LITERAL("m3u8"), "application/x-mpegurl", true },
29 #endif
30 { FILE_PATH_LITERAL("not an extension / for sure"), "", false },
33 std::string mime_type;
34 bool rv;
36 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
37 rv = GetMimeTypeFromExtension(tests[i].extension, &mime_type);
38 EXPECT_EQ(tests[i].valid, rv);
39 if (rv)
40 EXPECT_EQ(tests[i].mime_type, mime_type);
44 TEST(MimeUtilTest, FileTest) {
45 const struct {
46 const base::FilePath::CharType* file_path;
47 const char* mime_type;
48 bool valid;
49 } tests[] = {
50 { FILE_PATH_LITERAL("c:\\foo\\bar.css"), "text/css", true },
51 { FILE_PATH_LITERAL("c:\\blah"), "", false },
52 { FILE_PATH_LITERAL("/usr/local/bin/mplayer"), "", false },
53 { FILE_PATH_LITERAL("/home/foo/bar.css"), "text/css", true },
54 { FILE_PATH_LITERAL("/blah."), "", false },
55 { FILE_PATH_LITERAL("c:\\blah."), "", false },
58 std::string mime_type;
59 bool rv;
61 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
62 rv = GetMimeTypeFromFile(base::FilePath(tests[i].file_path),
63 &mime_type);
64 EXPECT_EQ(tests[i].valid, rv);
65 if (rv)
66 EXPECT_EQ(tests[i].mime_type, mime_type);
70 TEST(MimeUtilTest, LookupTypes) {
71 EXPECT_FALSE(IsUnsupportedTextMimeType("text/banana"));
72 EXPECT_TRUE(IsUnsupportedTextMimeType("text/vcard"));
74 EXPECT_TRUE(IsSupportedImageMimeType("image/jpeg"));
75 EXPECT_FALSE(IsSupportedImageMimeType("image/lolcat"));
76 EXPECT_TRUE(IsSupportedNonImageMimeType("text/html"));
77 EXPECT_TRUE(IsSupportedNonImageMimeType("text/css"));
78 EXPECT_TRUE(IsSupportedNonImageMimeType("text/"));
79 EXPECT_TRUE(IsSupportedNonImageMimeType("text/banana"));
80 EXPECT_FALSE(IsSupportedNonImageMimeType("text/vcard"));
81 EXPECT_FALSE(IsSupportedNonImageMimeType("application/virus"));
82 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-x509-user-cert"));
83 EXPECT_TRUE(IsSupportedNonImageMimeType("application/json"));
84 EXPECT_TRUE(IsSupportedNonImageMimeType("application/+json"));
85 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-suggestions+json"));
86 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-s+json;x=2"));
87 #if defined(OS_ANDROID)
88 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-x509-ca-cert"));
89 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-pkcs12"));
90 EXPECT_TRUE(IsSupportedMediaMimeType("application/vnd.apple.mpegurl"));
91 EXPECT_TRUE(IsSupportedMediaMimeType("application/x-mpegurl"));
92 #endif
94 EXPECT_TRUE(IsSupportedMimeType("image/jpeg"));
95 EXPECT_FALSE(IsSupportedMimeType("image/lolcat"));
96 EXPECT_TRUE(IsSupportedMimeType("text/html"));
97 EXPECT_TRUE(IsSupportedMimeType("text/banana"));
98 EXPECT_FALSE(IsSupportedMimeType("text/vcard"));
99 EXPECT_FALSE(IsSupportedMimeType("application/virus"));
100 EXPECT_FALSE(IsSupportedMimeType("application/x-json"));
101 EXPECT_FALSE(IsSupportedNonImageMimeType("application/vnd.doc;x=y+json"));
104 TEST(MimeUtilTest, StrictMediaMimeType) {
105 EXPECT_TRUE(IsStrictMediaMimeType("video/webm"));
106 EXPECT_TRUE(IsStrictMediaMimeType("audio/webm"));
108 EXPECT_TRUE(IsStrictMediaMimeType("audio/wav"));
109 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-wav"));
111 EXPECT_TRUE(IsStrictMediaMimeType("video/ogg"));
112 EXPECT_TRUE(IsStrictMediaMimeType("audio/ogg"));
113 EXPECT_TRUE(IsStrictMediaMimeType("application/ogg"));
115 EXPECT_TRUE(IsStrictMediaMimeType("audio/mpeg"));
116 EXPECT_TRUE(IsStrictMediaMimeType("audio/mp3"));
117 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-mp3"));
119 EXPECT_TRUE(IsStrictMediaMimeType("video/mp4"));
120 EXPECT_TRUE(IsStrictMediaMimeType("video/x-m4v"));
121 EXPECT_TRUE(IsStrictMediaMimeType("audio/mp4"));
122 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-m4a"));
124 EXPECT_TRUE(IsStrictMediaMimeType("application/x-mpegurl"));
125 EXPECT_TRUE(IsStrictMediaMimeType("application/vnd.apple.mpegurl"));
127 EXPECT_FALSE(IsStrictMediaMimeType("video/unknown"));
128 EXPECT_FALSE(IsStrictMediaMimeType("audio/unknown"));
129 EXPECT_FALSE(IsStrictMediaMimeType("application/unknown"));
130 EXPECT_FALSE(IsStrictMediaMimeType("unknown/unknown"));
133 TEST(MimeUtilTest, MatchesMimeType) {
134 EXPECT_TRUE(MatchesMimeType("*", "video/x-mpeg"));
135 EXPECT_TRUE(MatchesMimeType("video/*", "video/x-mpeg"));
136 EXPECT_TRUE(MatchesMimeType("video/*", "video/*"));
137 EXPECT_TRUE(MatchesMimeType("video/x-mpeg", "video/x-mpeg"));
138 EXPECT_TRUE(MatchesMimeType("application/*+xml",
139 "application/html+xml"));
140 EXPECT_TRUE(MatchesMimeType("application/*+xml", "application/+xml"));
141 EXPECT_TRUE(MatchesMimeType("application/*+json",
142 "application/x-myformat+json"));
143 EXPECT_TRUE(MatchesMimeType("aaa*aaa", "aaaaaa"));
144 EXPECT_TRUE(MatchesMimeType("*", std::string()));
145 EXPECT_FALSE(MatchesMimeType("video/", "video/x-mpeg"));
146 EXPECT_FALSE(MatchesMimeType(std::string(), "video/x-mpeg"));
147 EXPECT_FALSE(MatchesMimeType(std::string(), std::string()));
148 EXPECT_FALSE(MatchesMimeType("video/x-mpeg", std::string()));
149 EXPECT_FALSE(MatchesMimeType("application/*+xml", "application/xml"));
150 EXPECT_FALSE(MatchesMimeType("application/*+xml",
151 "application/html+xmlz"));
152 EXPECT_FALSE(MatchesMimeType("application/*+xml",
153 "applcation/html+xml"));
154 EXPECT_FALSE(MatchesMimeType("aaa*aaa", "aaaaa"));
156 EXPECT_TRUE(MatchesMimeType("*", "video/x-mpeg;param=val"));
157 EXPECT_TRUE(MatchesMimeType("video/*", "video/x-mpeg;param=val"));
158 EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/mpeg"));
159 EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/mpeg;param=other"));
160 EXPECT_TRUE(MatchesMimeType("video/*;param=val", "video/mpeg;param=val"));
161 EXPECT_TRUE(MatchesMimeType("video/x-mpeg", "video/x-mpeg;param=val"));
162 EXPECT_TRUE(MatchesMimeType("video/x-mpeg;param=val",
163 "video/x-mpeg;param=val"));
164 EXPECT_FALSE(MatchesMimeType("video/x-mpeg;param2=val2",
165 "video/x-mpeg;param=val"));
166 EXPECT_FALSE(MatchesMimeType("video/x-mpeg;param2=val2",
167 "video/x-mpeg;param2=val"));
168 EXPECT_TRUE(MatchesMimeType("video/x-mpeg;param=val",
169 "video/x-mpeg;param=val;param2=val2"));
170 EXPECT_TRUE(MatchesMimeType("video/x-mpeg;param=val;param2=val2",
171 "video/x-mpeg;param=val;param2=val2"));
172 EXPECT_TRUE(MatchesMimeType("video/x-mpeg;param2=val2;param=val",
173 "video/x-mpeg;param=val;param2=val2"));
174 EXPECT_FALSE(MatchesMimeType("video/x-mpeg;param3=val3;param=val",
175 "video/x-mpeg;param=val;param2=val2"));
176 EXPECT_TRUE(MatchesMimeType("video/x-mpeg;param=val ;param2=val2 ",
177 "video/x-mpeg;param=val;param2=val2"));
179 EXPECT_TRUE(MatchesMimeType("*/*;param=val", "video/x-mpeg;param=val"));
180 EXPECT_FALSE(MatchesMimeType("*/*;param=val", "video/x-mpeg;param=val2"));
182 EXPECT_TRUE(MatchesMimeType("*", "*"));
183 EXPECT_TRUE(MatchesMimeType("*", "*/*"));
184 EXPECT_TRUE(MatchesMimeType("*/*", "*/*"));
185 EXPECT_TRUE(MatchesMimeType("*/*", "*"));
186 EXPECT_TRUE(MatchesMimeType("video/*", "video/*"));
187 EXPECT_FALSE(MatchesMimeType("video/*", "*/*"));
188 EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/*"));
189 EXPECT_TRUE(MatchesMimeType("video/*;param=val", "video/*;param=val"));
190 EXPECT_FALSE(MatchesMimeType("video/*;param=val", "video/*;param=val2"));
192 EXPECT_TRUE(MatchesMimeType("ab*cd", "abxxxcd"));
193 EXPECT_TRUE(MatchesMimeType("ab*cd", "abx/xcd"));
194 EXPECT_TRUE(MatchesMimeType("ab/*cd", "ab/xxxcd"));
197 TEST(MimeUtilTest, CommonMediaMimeType) {
198 #if defined(OS_ANDROID)
199 bool HLSSupported;
200 if (base::android::BuildInfo::GetInstance()->sdk_int() < 14)
201 HLSSupported = false;
202 else
203 HLSSupported = true;
204 #endif
206 EXPECT_TRUE(IsSupportedMediaMimeType("audio/webm"));
207 EXPECT_TRUE(IsSupportedMediaMimeType("video/webm"));
209 EXPECT_TRUE(IsSupportedMediaMimeType("audio/wav"));
210 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-wav"));
212 EXPECT_TRUE(IsSupportedMediaMimeType("audio/ogg"));
213 EXPECT_TRUE(IsSupportedMediaMimeType("application/ogg"));
214 #if defined(OS_ANDROID)
215 EXPECT_FALSE(IsSupportedMediaMimeType("video/ogg"));
216 EXPECT_EQ(HLSSupported, IsSupportedMediaMimeType("application/x-mpegurl"));
217 EXPECT_EQ(HLSSupported,
218 IsSupportedMediaMimeType("application/vnd.apple.mpegurl"));
219 #else
220 EXPECT_TRUE(IsSupportedMediaMimeType("video/ogg"));
221 EXPECT_FALSE(IsSupportedMediaMimeType("application/x-mpegurl"));
222 EXPECT_FALSE(IsSupportedMediaMimeType("application/vnd.apple.mpegurl"));
223 #endif // OS_ANDROID
225 #if defined(USE_PROPRIETARY_CODECS)
226 EXPECT_TRUE(IsSupportedMediaMimeType("audio/mp4"));
227 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-m4a"));
228 EXPECT_TRUE(IsSupportedMediaMimeType("video/mp4"));
229 EXPECT_TRUE(IsSupportedMediaMimeType("video/x-m4v"));
231 EXPECT_TRUE(IsSupportedMediaMimeType("audio/mp3"));
232 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-mp3"));
233 EXPECT_TRUE(IsSupportedMediaMimeType("audio/mpeg"));
235 #if defined(ENABLE_MPEG2TS_STREAM_PARSER)
236 EXPECT_TRUE(IsSupportedMediaMimeType("video/mp2t"));
237 #else
238 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp2t"));
239 #endif
240 #else
241 EXPECT_FALSE(IsSupportedMediaMimeType("audio/mp4"));
242 EXPECT_FALSE(IsSupportedMediaMimeType("audio/x-m4a"));
243 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp4"));
244 EXPECT_FALSE(IsSupportedMediaMimeType("video/x-m4v"));
246 EXPECT_FALSE(IsSupportedMediaMimeType("audio/mp3"));
247 EXPECT_FALSE(IsSupportedMediaMimeType("audio/x-mp3"));
248 EXPECT_FALSE(IsSupportedMediaMimeType("audio/mpeg"));
249 #endif // USE_PROPRIETARY_CODECS
250 EXPECT_FALSE(IsSupportedMediaMimeType("video/mp3"));
252 EXPECT_FALSE(IsSupportedMediaMimeType("video/unknown"));
253 EXPECT_FALSE(IsSupportedMediaMimeType("audio/unknown"));
254 EXPECT_FALSE(IsSupportedMediaMimeType("unknown/unknown"));
257 // Note: codecs should only be a list of 2 or fewer; hence the restriction of
258 // results' length to 2.
259 TEST(MimeUtilTest, ParseCodecString) {
260 const struct {
261 const char* original;
262 size_t expected_size;
263 const char* results[2];
264 } tests[] = {
265 { "\"bogus\"", 1, { "bogus" } },
266 { "0", 1, { "0" } },
267 { "avc1.42E01E, mp4a.40.2", 2, { "avc1", "mp4a" } },
268 { "\"mp4v.20.240, mp4a.40.2\"", 2, { "mp4v", "mp4a" } },
269 { "mp4v.20.8, samr", 2, { "mp4v", "samr" } },
270 { "\"theora, vorbis\"", 2, { "theora", "vorbis" } },
271 { "", 0, { } },
272 { "\"\"", 0, { } },
273 { "\" \"", 0, { } },
274 { ",", 2, { "", "" } },
277 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
278 std::vector<std::string> codecs_out;
279 ParseCodecString(tests[i].original, &codecs_out, true);
280 ASSERT_EQ(tests[i].expected_size, codecs_out.size());
281 for (size_t j = 0; j < tests[i].expected_size; ++j)
282 EXPECT_EQ(tests[i].results[j], codecs_out[j]);
285 // Test without stripping the codec type.
286 std::vector<std::string> codecs_out;
287 ParseCodecString("avc1.42E01E, mp4a.40.2", &codecs_out, false);
288 ASSERT_EQ(2u, codecs_out.size());
289 EXPECT_EQ("avc1.42E01E", codecs_out[0]);
290 EXPECT_EQ("mp4a.40.2", codecs_out[1]);
293 TEST(MimeUtilTest, TestParseMimeTypeWithoutParameter) {
294 std::string nonAscii("application/nonutf8");
295 EXPECT_TRUE(ParseMimeTypeWithoutParameter(nonAscii, NULL, NULL));
296 #if defined(OS_WIN)
297 nonAscii.append(base::WideToUTF8(std::wstring(L"\u2603")));
298 #else
299 nonAscii.append("\u2603"); // unicode snowman
300 #endif
301 EXPECT_FALSE(ParseMimeTypeWithoutParameter(nonAscii, NULL, NULL));
303 std::string top_level_type;
304 std::string subtype;
305 EXPECT_TRUE(ParseMimeTypeWithoutParameter(
306 "application/mime", &top_level_type, &subtype));
307 EXPECT_EQ("application", top_level_type);
308 EXPECT_EQ("mime", subtype);
310 // Various allowed subtype forms.
311 EXPECT_TRUE(ParseMimeTypeWithoutParameter("application/json", NULL, NULL));
312 EXPECT_TRUE(ParseMimeTypeWithoutParameter(
313 "application/x-suggestions+json", NULL, NULL));
314 EXPECT_TRUE(ParseMimeTypeWithoutParameter("application/+json", NULL, NULL));
316 // Upper case letters are allowed.
317 EXPECT_TRUE(ParseMimeTypeWithoutParameter("text/mime", NULL, NULL));
318 EXPECT_TRUE(ParseMimeTypeWithoutParameter("TEXT/mime", NULL, NULL));
319 EXPECT_TRUE(ParseMimeTypeWithoutParameter("Text/mime", NULL, NULL));
320 EXPECT_TRUE(ParseMimeTypeWithoutParameter("TeXt/mime", NULL, NULL));
322 // Experimental types are also considered to be valid.
323 EXPECT_TRUE(ParseMimeTypeWithoutParameter("x-video/mime", NULL, NULL));
324 EXPECT_TRUE(ParseMimeTypeWithoutParameter("X-Video/mime", NULL, NULL));
326 EXPECT_FALSE(ParseMimeTypeWithoutParameter("text", NULL, NULL));
327 EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/", NULL, NULL));
328 EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/ ", NULL, NULL));
329 EXPECT_FALSE(ParseMimeTypeWithoutParameter("te(xt/ ", NULL, NULL));
330 EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/()plain", NULL, NULL));
332 EXPECT_FALSE(ParseMimeTypeWithoutParameter("x-video", NULL, NULL));
333 EXPECT_FALSE(ParseMimeTypeWithoutParameter("x-video/", NULL, NULL));
335 EXPECT_FALSE(ParseMimeTypeWithoutParameter("application/a/b/c", NULL, NULL));
337 //EXPECT_TRUE(ParseMimeTypeWithoutParameter("video/mime;parameter"));
340 TEST(MimeUtilTest, TestIsValidTopLevelMimeType) {
341 EXPECT_TRUE(IsValidTopLevelMimeType("application"));
342 EXPECT_TRUE(IsValidTopLevelMimeType("audio"));
343 EXPECT_TRUE(IsValidTopLevelMimeType("example"));
344 EXPECT_TRUE(IsValidTopLevelMimeType("image"));
345 EXPECT_TRUE(IsValidTopLevelMimeType("message"));
346 EXPECT_TRUE(IsValidTopLevelMimeType("model"));
347 EXPECT_TRUE(IsValidTopLevelMimeType("multipart"));
348 EXPECT_TRUE(IsValidTopLevelMimeType("text"));
349 EXPECT_TRUE(IsValidTopLevelMimeType("video"));
351 EXPECT_TRUE(IsValidTopLevelMimeType("TEXT"));
352 EXPECT_TRUE(IsValidTopLevelMimeType("Text"));
353 EXPECT_TRUE(IsValidTopLevelMimeType("TeXt"));
355 EXPECT_FALSE(IsValidTopLevelMimeType("mime"));
356 EXPECT_FALSE(IsValidTopLevelMimeType(""));
357 EXPECT_FALSE(IsValidTopLevelMimeType("/"));
358 EXPECT_FALSE(IsValidTopLevelMimeType(" "));
360 EXPECT_TRUE(IsValidTopLevelMimeType("x-video"));
361 EXPECT_TRUE(IsValidTopLevelMimeType("X-video"));
363 EXPECT_FALSE(IsValidTopLevelMimeType("x-"));
366 TEST(MimeUtilTest, TestToIANAMediaType) {
367 EXPECT_EQ("", GetIANAMediaType("texting/driving"));
368 EXPECT_EQ("", GetIANAMediaType("ham/sandwich"));
369 EXPECT_EQ("", GetIANAMediaType(std::string()));
370 EXPECT_EQ("", GetIANAMediaType("/application/hamsandwich"));
372 EXPECT_EQ("application", GetIANAMediaType("application/poodle-wrestler"));
373 EXPECT_EQ("audio", GetIANAMediaType("audio/mpeg"));
374 EXPECT_EQ("example", GetIANAMediaType("example/yomomma"));
375 EXPECT_EQ("image", GetIANAMediaType("image/png"));
376 EXPECT_EQ("message", GetIANAMediaType("message/sipfrag"));
377 EXPECT_EQ("model", GetIANAMediaType("model/vrml"));
378 EXPECT_EQ("multipart", GetIANAMediaType("multipart/mixed"));
379 EXPECT_EQ("text", GetIANAMediaType("text/plain"));
380 EXPECT_EQ("video", GetIANAMediaType("video/H261"));
383 TEST(MimeUtilTest, TestGetExtensionsForMimeType) {
384 const struct {
385 const char* mime_type;
386 size_t min_expected_size;
387 const char* contained_result;
388 } tests[] = {
389 { "text/plain", 2, "txt" },
390 { "*", 0, NULL },
391 { "message/*", 1, "eml" },
392 { "MeSsAge/*", 1, "eml" },
393 { "image/bmp", 1, "bmp" },
394 { "video/*", 6, "mp4" },
395 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_IOS)
396 { "video/*", 6, "mpg" },
397 #else
398 { "video/*", 6, "mpeg" },
399 #endif
400 { "audio/*", 6, "oga" },
401 { "aUDIo/*", 6, "wav" },
404 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
405 std::vector<base::FilePath::StringType> extensions;
406 GetExtensionsForMimeType(tests[i].mime_type, &extensions);
407 ASSERT_TRUE(tests[i].min_expected_size <= extensions.size());
409 if (!tests[i].contained_result)
410 continue;
412 bool found = false;
413 for (size_t j = 0; !found && j < extensions.size(); ++j) {
414 #if defined(OS_WIN)
415 if (extensions[j] == base::UTF8ToWide(tests[i].contained_result))
416 found = true;
417 #else
418 if (extensions[j] == tests[i].contained_result)
419 found = true;
420 #endif
422 ASSERT_TRUE(found) << "Must find at least the contained result within "
423 << tests[i].mime_type;
427 TEST(MimeUtilTest, TestGetCertificateMimeTypeForMimeType) {
428 EXPECT_EQ(CERTIFICATE_MIME_TYPE_X509_USER_CERT,
429 GetCertificateMimeTypeForMimeType("application/x-x509-user-cert"));
430 #if defined(OS_ANDROID)
431 // Only Android supports CA Certs and PKCS12 archives.
432 EXPECT_EQ(CERTIFICATE_MIME_TYPE_X509_CA_CERT,
433 GetCertificateMimeTypeForMimeType("application/x-x509-ca-cert"));
434 EXPECT_EQ(CERTIFICATE_MIME_TYPE_PKCS12_ARCHIVE,
435 GetCertificateMimeTypeForMimeType("application/x-pkcs12"));
436 #else
437 EXPECT_EQ(CERTIFICATE_MIME_TYPE_UNKNOWN,
438 GetCertificateMimeTypeForMimeType("application/x-x509-ca-cert"));
439 EXPECT_EQ(CERTIFICATE_MIME_TYPE_UNKNOWN,
440 GetCertificateMimeTypeForMimeType("application/x-pkcs12"));
441 #endif
442 EXPECT_EQ(CERTIFICATE_MIME_TYPE_UNKNOWN,
443 GetCertificateMimeTypeForMimeType("text/plain"));
446 TEST(MimeUtilTest, TestAddMultipartValueForUpload) {
447 const char* ref_output = "--boundary\r\nContent-Disposition: form-data;"
448 " name=\"value name\"\r\nContent-Type: content type"
449 "\r\n\r\nvalue\r\n"
450 "--boundary\r\nContent-Disposition: form-data;"
451 " name=\"value name\"\r\n\r\nvalue\r\n"
452 "--boundary--\r\n";
453 std::string post_data;
454 AddMultipartValueForUpload("value name", "value", "boundary",
455 "content type", &post_data);
456 AddMultipartValueForUpload("value name", "value", "boundary",
457 "", &post_data);
458 AddMultipartFinalDelimiterForUpload("boundary", &post_data);
459 EXPECT_STREQ(ref_output, post_data.c_str());
462 } // namespace net