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

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

Issue 97913002: Recognize json media types as (non-image) mime types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years 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
« net/base/mime_util.cc ('K') | « 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 EXPECT_TRUE(IsSupportedImageMimeType("image/jpeg")); 67 EXPECT_TRUE(IsSupportedImageMimeType("image/jpeg"));
68 EXPECT_FALSE(IsSupportedImageMimeType("image/lolcat")); 68 EXPECT_FALSE(IsSupportedImageMimeType("image/lolcat"));
69 EXPECT_TRUE(IsSupportedNonImageMimeType("text/html")); 69 EXPECT_TRUE(IsSupportedNonImageMimeType("text/html"));
70 EXPECT_TRUE(IsSupportedNonImageMimeType("text/css")); 70 EXPECT_TRUE(IsSupportedNonImageMimeType("text/css"));
71 EXPECT_TRUE(IsSupportedNonImageMimeType("text/")); 71 EXPECT_TRUE(IsSupportedNonImageMimeType("text/"));
72 EXPECT_TRUE(IsSupportedNonImageMimeType("text/banana")); 72 EXPECT_TRUE(IsSupportedNonImageMimeType("text/banana"));
73 EXPECT_FALSE(IsSupportedNonImageMimeType("text/vcard")); 73 EXPECT_FALSE(IsSupportedNonImageMimeType("text/vcard"));
74 EXPECT_FALSE(IsSupportedNonImageMimeType("application/virus")); 74 EXPECT_FALSE(IsSupportedNonImageMimeType("application/virus"));
75 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-x509-user-cert")); 75 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-x509-user-cert"));
76 EXPECT_TRUE(IsSupportedNonImageMimeType("application/json"));
77 EXPECT_TRUE(IsSupportedNonImageMimeType("application/+json"));
78 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-suggestions+json"));
79 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-s+json;x=2"));
76 #if defined(OS_ANDROID) 80 #if defined(OS_ANDROID)
77 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-x509-ca-cert")); 81 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-x509-ca-cert"));
78 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-pkcs12")); 82 EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-pkcs12"));
79 #endif 83 #endif
80 84
81 EXPECT_TRUE(IsSupportedMimeType("image/jpeg")); 85 EXPECT_TRUE(IsSupportedMimeType("image/jpeg"));
82 EXPECT_FALSE(IsSupportedMimeType("image/lolcat")); 86 EXPECT_FALSE(IsSupportedMimeType("image/lolcat"));
83 EXPECT_TRUE(IsSupportedMimeType("text/html")); 87 EXPECT_TRUE(IsSupportedMimeType("text/html"));
84 EXPECT_TRUE(IsSupportedMimeType("text/banana")); 88 EXPECT_TRUE(IsSupportedMimeType("text/banana"));
85 EXPECT_FALSE(IsSupportedMimeType("text/vcard")); 89 EXPECT_FALSE(IsSupportedMimeType("text/vcard"));
86 EXPECT_FALSE(IsSupportedMimeType("application/virus")); 90 EXPECT_FALSE(IsSupportedMimeType("application/virus"));
91 EXPECT_FALSE(IsSupportedMimeType("application/x-json"));
92 EXPECT_FALSE(IsSupportedNonImageMimeType("application/vnd.doc;x=y+json"));
87 } 93 }
88 94
89 TEST(MimeUtilTest, MatchesMimeType) { 95 TEST(MimeUtilTest, MatchesMimeType) {
90 EXPECT_TRUE(MatchesMimeType("*", "video/x-mpeg")); 96 EXPECT_TRUE(MatchesMimeType("*", "video/x-mpeg"));
91 EXPECT_TRUE(MatchesMimeType("video/*", "video/x-mpeg")); 97 EXPECT_TRUE(MatchesMimeType("video/*", "video/x-mpeg"));
92 EXPECT_TRUE(MatchesMimeType("video/*", "video/*")); 98 EXPECT_TRUE(MatchesMimeType("video/*", "video/*"));
93 EXPECT_TRUE(MatchesMimeType("video/x-mpeg", "video/x-mpeg")); 99 EXPECT_TRUE(MatchesMimeType("video/x-mpeg", "video/x-mpeg"));
94 EXPECT_TRUE(MatchesMimeType("application/*+xml", 100 EXPECT_TRUE(MatchesMimeType("application/*+xml",
95 "application/html+xml")); 101 "application/html+xml"));
96 EXPECT_TRUE(MatchesMimeType("application/*+xml", "application/+xml")); 102 EXPECT_TRUE(MatchesMimeType("application/*+xml", "application/+xml"));
103 EXPECT_TRUE(MatchesMimeType("application/*+json",
104 "application/x-myformat+json"));
97 EXPECT_TRUE(MatchesMimeType("aaa*aaa", "aaaaaa")); 105 EXPECT_TRUE(MatchesMimeType("aaa*aaa", "aaaaaa"));
98 EXPECT_TRUE(MatchesMimeType("*", std::string())); 106 EXPECT_TRUE(MatchesMimeType("*", std::string()));
99 EXPECT_FALSE(MatchesMimeType("video/", "video/x-mpeg")); 107 EXPECT_FALSE(MatchesMimeType("video/", "video/x-mpeg"));
100 EXPECT_FALSE(MatchesMimeType(std::string(), "video/x-mpeg")); 108 EXPECT_FALSE(MatchesMimeType(std::string(), "video/x-mpeg"));
101 EXPECT_FALSE(MatchesMimeType(std::string(), std::string())); 109 EXPECT_FALSE(MatchesMimeType(std::string(), std::string()));
102 EXPECT_FALSE(MatchesMimeType("video/x-mpeg", std::string())); 110 EXPECT_FALSE(MatchesMimeType("video/x-mpeg", std::string()));
103 EXPECT_FALSE(MatchesMimeType("application/*+xml", "application/xml")); 111 EXPECT_FALSE(MatchesMimeType("application/*+xml", "application/xml"));
104 EXPECT_FALSE(MatchesMimeType("application/*+xml", 112 EXPECT_FALSE(MatchesMimeType("application/*+xml",
105 "application/html+xmlz")); 113 "application/html+xmlz"));
106 EXPECT_FALSE(MatchesMimeType("application/*+xml", 114 EXPECT_FALSE(MatchesMimeType("application/*+xml",
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 std::string nonAscii("application/nonutf8"); 196 std::string nonAscii("application/nonutf8");
189 EXPECT_TRUE(IsMimeType(nonAscii)); 197 EXPECT_TRUE(IsMimeType(nonAscii));
190 #if defined(OS_WIN) 198 #if defined(OS_WIN)
191 nonAscii.append(WideToUTF8(std::wstring(L"\u2603"))); 199 nonAscii.append(WideToUTF8(std::wstring(L"\u2603")));
192 #else 200 #else
193 nonAscii.append("\u2603"); // unicode snowman 201 nonAscii.append("\u2603"); // unicode snowman
194 #endif 202 #endif
195 EXPECT_FALSE(IsMimeType(nonAscii)); 203 EXPECT_FALSE(IsMimeType(nonAscii));
196 204
197 EXPECT_TRUE(IsMimeType("application/mime")); 205 EXPECT_TRUE(IsMimeType("application/mime"));
206 EXPECT_TRUE(IsMimeType("application/json"));
207 EXPECT_TRUE(IsMimeType("application/x-suggestions+json"));
208 EXPECT_TRUE(IsMimeType("application/+json"));
198 EXPECT_TRUE(IsMimeType("audio/mime")); 209 EXPECT_TRUE(IsMimeType("audio/mime"));
199 EXPECT_TRUE(IsMimeType("example/mime")); 210 EXPECT_TRUE(IsMimeType("example/mime"));
200 EXPECT_TRUE(IsMimeType("image/mime")); 211 EXPECT_TRUE(IsMimeType("image/mime"));
201 EXPECT_TRUE(IsMimeType("message/mime")); 212 EXPECT_TRUE(IsMimeType("message/mime"));
202 EXPECT_TRUE(IsMimeType("model/mime")); 213 EXPECT_TRUE(IsMimeType("model/mime"));
203 EXPECT_TRUE(IsMimeType("multipart/mime")); 214 EXPECT_TRUE(IsMimeType("multipart/mime"));
204 EXPECT_TRUE(IsMimeType("text/mime")); 215 EXPECT_TRUE(IsMimeType("text/mime"));
205 EXPECT_TRUE(IsMimeType("TEXT/mime")); 216 EXPECT_TRUE(IsMimeType("TEXT/mime"));
206 EXPECT_TRUE(IsMimeType("Text/mime")); 217 EXPECT_TRUE(IsMimeType("Text/mime"));
207 EXPECT_TRUE(IsMimeType("TeXt/mime")); 218 EXPECT_TRUE(IsMimeType("TeXt/mime"));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 std::string post_data; 319 std::string post_data;
309 AddMultipartValueForUpload("value name", "value", "boundary", 320 AddMultipartValueForUpload("value name", "value", "boundary",
310 "content type", &post_data); 321 "content type", &post_data);
311 AddMultipartValueForUpload("value name", "value", "boundary", 322 AddMultipartValueForUpload("value name", "value", "boundary",
312 "", &post_data); 323 "", &post_data);
313 AddMultipartFinalDelimiterForUpload("boundary", &post_data); 324 AddMultipartFinalDelimiterForUpload("boundary", &post_data);
314 EXPECT_STREQ(ref_output, post_data.c_str()); 325 EXPECT_STREQ(ref_output, post_data.c_str());
315 } 326 }
316 327
317 } // namespace net 328 } // namespace net
OLDNEW
« net/base/mime_util.cc ('K') | « net/base/mime_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698