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

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

Issue 54233002: Make net::DataURL's MIME string check stricter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CONTENT_EXPORT Created 6 years, 9 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 | Annotate | Revision Log
« net/base/mime_util.h ('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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 187 }
188 188
189 // Test without stripping the codec type. 189 // Test without stripping the codec type.
190 std::vector<std::string> codecs_out; 190 std::vector<std::string> codecs_out;
191 ParseCodecString("avc1.42E01E, mp4a.40.2", &codecs_out, false); 191 ParseCodecString("avc1.42E01E, mp4a.40.2", &codecs_out, false);
192 ASSERT_EQ(2u, codecs_out.size()); 192 ASSERT_EQ(2u, codecs_out.size());
193 EXPECT_EQ("avc1.42E01E", codecs_out[0]); 193 EXPECT_EQ("avc1.42E01E", codecs_out[0]);
194 EXPECT_EQ("mp4a.40.2", codecs_out[1]); 194 EXPECT_EQ("mp4a.40.2", codecs_out[1]);
195 } 195 }
196 196
197 TEST(MimeUtilTest, TestIsMimeType) { 197 TEST(MimeUtilTest, TestParseMimeTypeWithoutParameter) {
198 std::string nonAscii("application/nonutf8"); 198 std::string nonAscii("application/nonutf8");
199 EXPECT_TRUE(IsMimeType(nonAscii)); 199 EXPECT_TRUE(ParseMimeTypeWithoutParameter(nonAscii, NULL, NULL));
200 #if defined(OS_WIN) 200 #if defined(OS_WIN)
201 nonAscii.append(base::WideToUTF8(std::wstring(L"\u2603"))); 201 nonAscii.append(base::WideToUTF8(std::wstring(L"\u2603")));
202 #else 202 #else
203 nonAscii.append("\u2603"); // unicode snowman 203 nonAscii.append("\u2603"); // unicode snowman
204 #endif 204 #endif
205 EXPECT_FALSE(IsMimeType(nonAscii)); 205 EXPECT_FALSE(ParseMimeTypeWithoutParameter(nonAscii, NULL, NULL));
206 206
207 EXPECT_TRUE(IsMimeType("application/mime")); 207 std::string top_level_type;
208 EXPECT_TRUE(IsMimeType("application/json")); 208 std::string subtype;
209 EXPECT_TRUE(IsMimeType("application/x-suggestions+json")); 209 EXPECT_TRUE(ParseMimeTypeWithoutParameter(
210 EXPECT_TRUE(IsMimeType("application/+json")); 210 "application/mime", &top_level_type, &subtype));
211 EXPECT_TRUE(IsMimeType("audio/mime")); 211 EXPECT_EQ("application", top_level_type);
212 EXPECT_TRUE(IsMimeType("example/mime")); 212 EXPECT_EQ("mime", subtype);
213 EXPECT_TRUE(IsMimeType("image/mime"));
214 EXPECT_TRUE(IsMimeType("message/mime"));
215 EXPECT_TRUE(IsMimeType("model/mime"));
216 EXPECT_TRUE(IsMimeType("multipart/mime"));
217 EXPECT_TRUE(IsMimeType("text/mime"));
218 EXPECT_TRUE(IsMimeType("TEXT/mime"));
219 EXPECT_TRUE(IsMimeType("Text/mime"));
220 EXPECT_TRUE(IsMimeType("TeXt/mime"));
221 EXPECT_TRUE(IsMimeType("video/mime"));
222 EXPECT_TRUE(IsMimeType("video/mime;parameter"));
223 EXPECT_TRUE(IsMimeType("*/*"));
224 EXPECT_TRUE(IsMimeType("*"));
225 213
226 EXPECT_TRUE(IsMimeType("x-video/mime")); 214 // Various allowed subtype forms.
227 EXPECT_TRUE(IsMimeType("X-Video/mime")); 215 EXPECT_TRUE(ParseMimeTypeWithoutParameter("application/json", NULL, NULL));
228 EXPECT_FALSE(IsMimeType("x-video/")); 216 EXPECT_TRUE(ParseMimeTypeWithoutParameter(
229 EXPECT_FALSE(IsMimeType("x-/mime")); 217 "application/x-suggestions+json", NULL, NULL));
230 EXPECT_FALSE(IsMimeType("mime/looking")); 218 EXPECT_TRUE(ParseMimeTypeWithoutParameter("application/+json", NULL, NULL));
231 EXPECT_FALSE(IsMimeType("text/")); 219
220 // Upper case letters are allowed.
221 EXPECT_TRUE(ParseMimeTypeWithoutParameter("text/mime", NULL, NULL));
222 EXPECT_TRUE(ParseMimeTypeWithoutParameter("TEXT/mime", NULL, NULL));
223 EXPECT_TRUE(ParseMimeTypeWithoutParameter("Text/mime", NULL, NULL));
224 EXPECT_TRUE(ParseMimeTypeWithoutParameter("TeXt/mime", NULL, NULL));
225
226 // Experimental types are also considered to be valid.
227 EXPECT_TRUE(ParseMimeTypeWithoutParameter("x-video/mime", NULL, NULL));
228 EXPECT_TRUE(ParseMimeTypeWithoutParameter("X-Video/mime", NULL, NULL));
229
230 EXPECT_FALSE(ParseMimeTypeWithoutParameter("text", NULL, NULL));
231 EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/", NULL, NULL));
232 EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/ ", NULL, NULL));
233 EXPECT_FALSE(ParseMimeTypeWithoutParameter("te(xt/ ", NULL, NULL));
234 EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/()plain", NULL, NULL));
235
236 EXPECT_FALSE(ParseMimeTypeWithoutParameter("x-video", NULL, NULL));
237 EXPECT_FALSE(ParseMimeTypeWithoutParameter("x-video/", NULL, NULL));
238
239 EXPECT_FALSE(ParseMimeTypeWithoutParameter("application/a/b/c", NULL, NULL));
240
241 //EXPECT_TRUE(ParseMimeTypeWithoutParameter("video/mime;parameter"));
242 }
243
244 TEST(MimeUtilTest, TestIsValidTopLevelMimeType) {
245 EXPECT_TRUE(IsValidTopLevelMimeType("application"));
246 EXPECT_TRUE(IsValidTopLevelMimeType("audio"));
247 EXPECT_TRUE(IsValidTopLevelMimeType("example"));
248 EXPECT_TRUE(IsValidTopLevelMimeType("image"));
249 EXPECT_TRUE(IsValidTopLevelMimeType("message"));
250 EXPECT_TRUE(IsValidTopLevelMimeType("model"));
251 EXPECT_TRUE(IsValidTopLevelMimeType("multipart"));
252 EXPECT_TRUE(IsValidTopLevelMimeType("text"));
253 EXPECT_TRUE(IsValidTopLevelMimeType("video"));
254
255 EXPECT_TRUE(IsValidTopLevelMimeType("TEXT"));
256 EXPECT_TRUE(IsValidTopLevelMimeType("Text"));
257 EXPECT_TRUE(IsValidTopLevelMimeType("TeXt"));
258
259 EXPECT_FALSE(IsValidTopLevelMimeType("mime"));
260 EXPECT_FALSE(IsValidTopLevelMimeType(""));
261 EXPECT_FALSE(IsValidTopLevelMimeType("/"));
262 EXPECT_FALSE(IsValidTopLevelMimeType(" "));
263
264 EXPECT_TRUE(IsValidTopLevelMimeType("x-video"));
265 EXPECT_TRUE(IsValidTopLevelMimeType("X-video"));
266
267 EXPECT_FALSE(IsValidTopLevelMimeType("x-"));
232 } 268 }
233 269
234 TEST(MimeUtilTest, TestToIANAMediaType) { 270 TEST(MimeUtilTest, TestToIANAMediaType) {
235 EXPECT_EQ("", GetIANAMediaType("texting/driving")); 271 EXPECT_EQ("", GetIANAMediaType("texting/driving"));
236 EXPECT_EQ("", GetIANAMediaType("ham/sandwich")); 272 EXPECT_EQ("", GetIANAMediaType("ham/sandwich"));
237 EXPECT_EQ("", GetIANAMediaType(std::string())); 273 EXPECT_EQ("", GetIANAMediaType(std::string()));
238 EXPECT_EQ("", GetIANAMediaType("/application/hamsandwich")); 274 EXPECT_EQ("", GetIANAMediaType("/application/hamsandwich"));
239 275
240 EXPECT_EQ("application", GetIANAMediaType("application/poodle-wrestler")); 276 EXPECT_EQ("application", GetIANAMediaType("application/poodle-wrestler"));
241 EXPECT_EQ("audio", GetIANAMediaType("audio/mpeg")); 277 EXPECT_EQ("audio", GetIANAMediaType("audio/mpeg"));
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 std::string post_data; 357 std::string post_data;
322 AddMultipartValueForUpload("value name", "value", "boundary", 358 AddMultipartValueForUpload("value name", "value", "boundary",
323 "content type", &post_data); 359 "content type", &post_data);
324 AddMultipartValueForUpload("value name", "value", "boundary", 360 AddMultipartValueForUpload("value name", "value", "boundary",
325 "", &post_data); 361 "", &post_data);
326 AddMultipartFinalDelimiterForUpload("boundary", &post_data); 362 AddMultipartFinalDelimiterForUpload("boundary", &post_data);
327 EXPECT_STREQ(ref_output, post_data.c_str()); 363 EXPECT_STREQ(ref_output, post_data.c_str());
328 } 364 }
329 365
330 } // namespace net 366 } // namespace net
OLDNEW
« net/base/mime_util.h ('K') | « net/base/mime_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698