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

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: Split web_url_loader_impl change Created 6 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 | Annotate | Revision Log
« 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 } 276 }
277 277
278 // Test without stripping the codec type. 278 // Test without stripping the codec type.
279 std::vector<std::string> codecs_out; 279 std::vector<std::string> codecs_out;
280 ParseCodecString("avc1.42E01E, mp4a.40.2", &codecs_out, false); 280 ParseCodecString("avc1.42E01E, mp4a.40.2", &codecs_out, false);
281 ASSERT_EQ(2u, codecs_out.size()); 281 ASSERT_EQ(2u, codecs_out.size());
282 EXPECT_EQ("avc1.42E01E", codecs_out[0]); 282 EXPECT_EQ("avc1.42E01E", codecs_out[0]);
283 EXPECT_EQ("mp4a.40.2", codecs_out[1]); 283 EXPECT_EQ("mp4a.40.2", codecs_out[1]);
284 } 284 }
285 285
286 TEST(MimeUtilTest, TestIsMimeType) { 286 TEST(MimeUtilTest, TestParseMimeTypeWithoutParameter) {
287 std::string nonAscii("application/nonutf8"); 287 std::string nonAscii("application/nonutf8");
288 EXPECT_TRUE(IsMimeType(nonAscii)); 288 EXPECT_TRUE(ParseMimeTypeWithoutParameter(nonAscii, NULL, NULL));
289 #if defined(OS_WIN) 289 #if defined(OS_WIN)
290 nonAscii.append(base::WideToUTF8(std::wstring(L"\u2603"))); 290 nonAscii.append(base::WideToUTF8(std::wstring(L"\u2603")));
291 #else 291 #else
292 nonAscii.append("\u2603"); // unicode snowman 292 nonAscii.append("\u2603"); // unicode snowman
293 #endif 293 #endif
294 EXPECT_FALSE(IsMimeType(nonAscii)); 294 EXPECT_FALSE(ParseMimeTypeWithoutParameter(nonAscii, NULL, NULL));
295 295
296 EXPECT_TRUE(IsMimeType("application/mime")); 296 std::string top_level_type;
297 EXPECT_TRUE(IsMimeType("application/json")); 297 std::string subtype;
298 EXPECT_TRUE(IsMimeType("application/x-suggestions+json")); 298 EXPECT_TRUE(ParseMimeTypeWithoutParameter(
299 EXPECT_TRUE(IsMimeType("application/+json")); 299 "application/mime", &top_level_type, &subtype));
300 EXPECT_TRUE(IsMimeType("audio/mime")); 300 EXPECT_EQ("application", top_level_type);
301 EXPECT_TRUE(IsMimeType("example/mime")); 301 EXPECT_EQ("mime", subtype);
302 EXPECT_TRUE(IsMimeType("image/mime"));
303 EXPECT_TRUE(IsMimeType("message/mime"));
304 EXPECT_TRUE(IsMimeType("model/mime"));
305 EXPECT_TRUE(IsMimeType("multipart/mime"));
306 EXPECT_TRUE(IsMimeType("text/mime"));
307 EXPECT_TRUE(IsMimeType("TEXT/mime"));
308 EXPECT_TRUE(IsMimeType("Text/mime"));
309 EXPECT_TRUE(IsMimeType("TeXt/mime"));
310 EXPECT_TRUE(IsMimeType("video/mime"));
311 EXPECT_TRUE(IsMimeType("video/mime;parameter"));
312 EXPECT_TRUE(IsMimeType("*/*"));
313 EXPECT_TRUE(IsMimeType("*"));
314 302
315 EXPECT_TRUE(IsMimeType("x-video/mime")); 303 // Various allowed subtype forms.
316 EXPECT_TRUE(IsMimeType("X-Video/mime")); 304 EXPECT_TRUE(ParseMimeTypeWithoutParameter("application/json", NULL, NULL));
317 EXPECT_FALSE(IsMimeType("x-video/")); 305 EXPECT_TRUE(ParseMimeTypeWithoutParameter(
318 EXPECT_FALSE(IsMimeType("x-/mime")); 306 "application/x-suggestions+json", NULL, NULL));
319 EXPECT_FALSE(IsMimeType("mime/looking")); 307 EXPECT_TRUE(ParseMimeTypeWithoutParameter("application/+json", NULL, NULL));
320 EXPECT_FALSE(IsMimeType("text/")); 308
309 // Upper case letters are allowed.
310 EXPECT_TRUE(ParseMimeTypeWithoutParameter("text/mime", NULL, NULL));
311 EXPECT_TRUE(ParseMimeTypeWithoutParameter("TEXT/mime", NULL, NULL));
312 EXPECT_TRUE(ParseMimeTypeWithoutParameter("Text/mime", NULL, NULL));
313 EXPECT_TRUE(ParseMimeTypeWithoutParameter("TeXt/mime", NULL, NULL));
314
315 // Experimental types are also considered to be valid.
316 EXPECT_TRUE(ParseMimeTypeWithoutParameter("x-video/mime", NULL, NULL));
317 EXPECT_TRUE(ParseMimeTypeWithoutParameter("X-Video/mime", NULL, NULL));
318
319 EXPECT_FALSE(ParseMimeTypeWithoutParameter("text", NULL, NULL));
320 EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/", NULL, NULL));
321 EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/ ", NULL, NULL));
322 EXPECT_FALSE(ParseMimeTypeWithoutParameter("te(xt/ ", NULL, NULL));
323 EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/()plain", NULL, NULL));
324
325 EXPECT_FALSE(ParseMimeTypeWithoutParameter("x-video", NULL, NULL));
326 EXPECT_FALSE(ParseMimeTypeWithoutParameter("x-video/", NULL, NULL));
327
328 EXPECT_FALSE(ParseMimeTypeWithoutParameter("application/a/b/c", NULL, NULL));
329
330 //EXPECT_TRUE(ParseMimeTypeWithoutParameter("video/mime;parameter"));
331 }
332
333 TEST(MimeUtilTest, TestIsValidTopLevelMimeType) {
334 EXPECT_TRUE(IsValidTopLevelMimeType("application"));
335 EXPECT_TRUE(IsValidTopLevelMimeType("audio"));
336 EXPECT_TRUE(IsValidTopLevelMimeType("example"));
337 EXPECT_TRUE(IsValidTopLevelMimeType("image"));
338 EXPECT_TRUE(IsValidTopLevelMimeType("message"));
339 EXPECT_TRUE(IsValidTopLevelMimeType("model"));
340 EXPECT_TRUE(IsValidTopLevelMimeType("multipart"));
341 EXPECT_TRUE(IsValidTopLevelMimeType("text"));
342 EXPECT_TRUE(IsValidTopLevelMimeType("video"));
343
344 EXPECT_TRUE(IsValidTopLevelMimeType("TEXT"));
345 EXPECT_TRUE(IsValidTopLevelMimeType("Text"));
346 EXPECT_TRUE(IsValidTopLevelMimeType("TeXt"));
347
348 EXPECT_FALSE(IsValidTopLevelMimeType("mime"));
349 EXPECT_FALSE(IsValidTopLevelMimeType(""));
350 EXPECT_FALSE(IsValidTopLevelMimeType("/"));
351 EXPECT_FALSE(IsValidTopLevelMimeType(" "));
352
353 EXPECT_TRUE(IsValidTopLevelMimeType("x-video"));
354 EXPECT_TRUE(IsValidTopLevelMimeType("X-video"));
355
356 EXPECT_FALSE(IsValidTopLevelMimeType("x-"));
321 } 357 }
322 358
323 TEST(MimeUtilTest, TestToIANAMediaType) { 359 TEST(MimeUtilTest, TestToIANAMediaType) {
324 EXPECT_EQ("", GetIANAMediaType("texting/driving")); 360 EXPECT_EQ("", GetIANAMediaType("texting/driving"));
325 EXPECT_EQ("", GetIANAMediaType("ham/sandwich")); 361 EXPECT_EQ("", GetIANAMediaType("ham/sandwich"));
326 EXPECT_EQ("", GetIANAMediaType(std::string())); 362 EXPECT_EQ("", GetIANAMediaType(std::string()));
327 EXPECT_EQ("", GetIANAMediaType("/application/hamsandwich")); 363 EXPECT_EQ("", GetIANAMediaType("/application/hamsandwich"));
328 364
329 EXPECT_EQ("application", GetIANAMediaType("application/poodle-wrestler")); 365 EXPECT_EQ("application", GetIANAMediaType("application/poodle-wrestler"));
330 EXPECT_EQ("audio", GetIANAMediaType("audio/mpeg")); 366 EXPECT_EQ("audio", GetIANAMediaType("audio/mpeg"));
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 std::string post_data; 446 std::string post_data;
411 AddMultipartValueForUpload("value name", "value", "boundary", 447 AddMultipartValueForUpload("value name", "value", "boundary",
412 "content type", &post_data); 448 "content type", &post_data);
413 AddMultipartValueForUpload("value name", "value", "boundary", 449 AddMultipartValueForUpload("value name", "value", "boundary",
414 "", &post_data); 450 "", &post_data);
415 AddMultipartFinalDelimiterForUpload("boundary", &post_data); 451 AddMultipartFinalDelimiterForUpload("boundary", &post_data);
416 EXPECT_STREQ(ref_output, post_data.c_str()); 452 EXPECT_STREQ(ref_output, post_data.c_str());
417 } 453 }
418 454
419 } // namespace net 455 } // 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