Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: net/base/mime_util_unittest.cc

Issue 1110833003: Move the IsSupported* mime functions out of //net and into //components/mime_util (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/base/mime_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 for (size_t i = 0; i < arraysize(tests); ++i) { 63 for (size_t i = 0; i < arraysize(tests); ++i) {
64 rv = GetMimeTypeFromFile(base::FilePath(tests[i].file_path), 64 rv = GetMimeTypeFromFile(base::FilePath(tests[i].file_path),
65 &mime_type); 65 &mime_type);
66 EXPECT_EQ(tests[i].valid, rv); 66 EXPECT_EQ(tests[i].valid, rv);
67 if (rv) 67 if (rv)
68 EXPECT_EQ(tests[i].mime_type, mime_type); 68 EXPECT_EQ(tests[i].mime_type, mime_type);
69 } 69 }
70 } 70 }
71 71
72 TEST(MimeUtilTest, LookupTypes) { 72 TEST(MimeUtilTest, LookupTypes) {
73 EXPECT_FALSE(IsUnsupportedTextMimeType("text/banana"));
74 EXPECT_TRUE(IsUnsupportedTextMimeType("text/vcard"));
75
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) 73 #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")); 74 EXPECT_TRUE(IsSupportedMediaMimeType("application/vnd.apple.mpegurl"));
97 EXPECT_TRUE(IsSupportedMediaMimeType("application/x-mpegurl")); 75 EXPECT_TRUE(IsSupportedMediaMimeType("application/x-mpegurl"));
98 EXPECT_TRUE(IsSupportedMediaMimeType("Application/X-MPEGURL")); 76 EXPECT_TRUE(IsSupportedMediaMimeType("Application/X-MPEGURL"));
99 #endif 77 #endif
100
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"));
113 } 78 }
114 79
115 TEST(MimeUtilTest, StrictMediaMimeType) { 80 TEST(MimeUtilTest, StrictMediaMimeType) {
116 EXPECT_TRUE(IsStrictMediaMimeType("video/webm")); 81 EXPECT_TRUE(IsStrictMediaMimeType("video/webm"));
117 EXPECT_TRUE(IsStrictMediaMimeType("Video/WEBM")); 82 EXPECT_TRUE(IsStrictMediaMimeType("Video/WEBM"));
118 EXPECT_TRUE(IsStrictMediaMimeType("audio/webm")); 83 EXPECT_TRUE(IsStrictMediaMimeType("audio/webm"));
119 84
120 EXPECT_TRUE(IsStrictMediaMimeType("audio/wav")); 85 EXPECT_TRUE(IsStrictMediaMimeType("audio/wav"));
121 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-wav")); 86 EXPECT_TRUE(IsStrictMediaMimeType("audio/x-wav"));
122 87
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 #else 395 #else
431 if (extensions[j] == tests[i].contained_result) 396 if (extensions[j] == tests[i].contained_result)
432 found = true; 397 found = true;
433 #endif 398 #endif
434 } 399 }
435 ASSERT_TRUE(found) << "Must find at least the contained result within " 400 ASSERT_TRUE(found) << "Must find at least the contained result within "
436 << tests[i].mime_type; 401 << tests[i].mime_type;
437 } 402 }
438 } 403 }
439 404
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"));
451 #else
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"));
456 #endif
457 EXPECT_EQ(CERTIFICATE_MIME_TYPE_UNKNOWN,
458 GetCertificateMimeTypeForMimeType("text/plain"));
459 }
460 405
461 TEST(MimeUtilTest, TestAddMultipartValueForUpload) { 406 TEST(MimeUtilTest, TestAddMultipartValueForUpload) {
462 const char ref_output[] = 407 const char ref_output[] =
463 "--boundary\r\nContent-Disposition: form-data;" 408 "--boundary\r\nContent-Disposition: form-data;"
464 " name=\"value name\"\r\nContent-Type: content type" 409 " name=\"value name\"\r\nContent-Type: content type"
465 "\r\n\r\nvalue\r\n" 410 "\r\n\r\nvalue\r\n"
466 "--boundary\r\nContent-Disposition: form-data;" 411 "--boundary\r\nContent-Disposition: form-data;"
467 " name=\"value name\"\r\n\r\nvalue\r\n" 412 " name=\"value name\"\r\n\r\nvalue\r\n"
468 "--boundary--\r\n"; 413 "--boundary--\r\n";
469 std::string post_data; 414 std::string post_data;
470 AddMultipartValueForUpload("value name", "value", "boundary", 415 AddMultipartValueForUpload("value name", "value", "boundary",
471 "content type", &post_data); 416 "content type", &post_data);
472 AddMultipartValueForUpload("value name", "value", "boundary", 417 AddMultipartValueForUpload("value name", "value", "boundary",
473 "", &post_data); 418 "", &post_data);
474 AddMultipartFinalDelimiterForUpload("boundary", &post_data); 419 AddMultipartFinalDelimiterForUpload("boundary", &post_data);
475 EXPECT_STREQ(ref_output, post_data.c_str()); 420 EXPECT_STREQ(ref_output, post_data.c_str());
476 } 421 }
477 422
478 } // namespace net 423 } // namespace net
OLDNEW
« no previous file with comments | « net/base/mime_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698