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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/mime_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/mime_util_unittest.cc
diff --git a/net/base/mime_util_unittest.cc b/net/base/mime_util_unittest.cc
index 61719889034a7ea3c7610f836063b082d23c16e7..bb783af90f36f9e649385619792ee839b171f165 100644
--- a/net/base/mime_util_unittest.cc
+++ b/net/base/mime_util_unittest.cc
@@ -283,41 +283,77 @@ TEST(MimeUtilTest, ParseCodecString) {
EXPECT_EQ("mp4a.40.2", codecs_out[1]);
}
-TEST(MimeUtilTest, TestIsMimeType) {
+TEST(MimeUtilTest, TestParseMimeTypeWithoutParameter) {
std::string nonAscii("application/nonutf8");
- EXPECT_TRUE(IsMimeType(nonAscii));
+ EXPECT_TRUE(ParseMimeTypeWithoutParameter(nonAscii, NULL, NULL));
#if defined(OS_WIN)
nonAscii.append(base::WideToUTF8(std::wstring(L"\u2603")));
#else
nonAscii.append("\u2603"); // unicode snowman
#endif
- EXPECT_FALSE(IsMimeType(nonAscii));
-
- EXPECT_TRUE(IsMimeType("application/mime"));
- EXPECT_TRUE(IsMimeType("application/json"));
- EXPECT_TRUE(IsMimeType("application/x-suggestions+json"));
- EXPECT_TRUE(IsMimeType("application/+json"));
- EXPECT_TRUE(IsMimeType("audio/mime"));
- EXPECT_TRUE(IsMimeType("example/mime"));
- EXPECT_TRUE(IsMimeType("image/mime"));
- EXPECT_TRUE(IsMimeType("message/mime"));
- EXPECT_TRUE(IsMimeType("model/mime"));
- EXPECT_TRUE(IsMimeType("multipart/mime"));
- EXPECT_TRUE(IsMimeType("text/mime"));
- EXPECT_TRUE(IsMimeType("TEXT/mime"));
- EXPECT_TRUE(IsMimeType("Text/mime"));
- EXPECT_TRUE(IsMimeType("TeXt/mime"));
- EXPECT_TRUE(IsMimeType("video/mime"));
- EXPECT_TRUE(IsMimeType("video/mime;parameter"));
- EXPECT_TRUE(IsMimeType("*/*"));
- EXPECT_TRUE(IsMimeType("*"));
-
- EXPECT_TRUE(IsMimeType("x-video/mime"));
- EXPECT_TRUE(IsMimeType("X-Video/mime"));
- EXPECT_FALSE(IsMimeType("x-video/"));
- EXPECT_FALSE(IsMimeType("x-/mime"));
- EXPECT_FALSE(IsMimeType("mime/looking"));
- EXPECT_FALSE(IsMimeType("text/"));
+ EXPECT_FALSE(ParseMimeTypeWithoutParameter(nonAscii, NULL, NULL));
+
+ std::string top_level_type;
+ std::string subtype;
+ EXPECT_TRUE(ParseMimeTypeWithoutParameter(
+ "application/mime", &top_level_type, &subtype));
+ EXPECT_EQ("application", top_level_type);
+ EXPECT_EQ("mime", subtype);
+
+ // Various allowed subtype forms.
+ EXPECT_TRUE(ParseMimeTypeWithoutParameter("application/json", NULL, NULL));
+ EXPECT_TRUE(ParseMimeTypeWithoutParameter(
+ "application/x-suggestions+json", NULL, NULL));
+ EXPECT_TRUE(ParseMimeTypeWithoutParameter("application/+json", NULL, NULL));
+
+ // Upper case letters are allowed.
+ EXPECT_TRUE(ParseMimeTypeWithoutParameter("text/mime", NULL, NULL));
+ EXPECT_TRUE(ParseMimeTypeWithoutParameter("TEXT/mime", NULL, NULL));
+ EXPECT_TRUE(ParseMimeTypeWithoutParameter("Text/mime", NULL, NULL));
+ EXPECT_TRUE(ParseMimeTypeWithoutParameter("TeXt/mime", NULL, NULL));
+
+ // Experimental types are also considered to be valid.
+ EXPECT_TRUE(ParseMimeTypeWithoutParameter("x-video/mime", NULL, NULL));
+ EXPECT_TRUE(ParseMimeTypeWithoutParameter("X-Video/mime", NULL, NULL));
+
+ EXPECT_FALSE(ParseMimeTypeWithoutParameter("text", NULL, NULL));
+ EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/", NULL, NULL));
+ EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/ ", NULL, NULL));
+ EXPECT_FALSE(ParseMimeTypeWithoutParameter("te(xt/ ", NULL, NULL));
+ EXPECT_FALSE(ParseMimeTypeWithoutParameter("text/()plain", NULL, NULL));
+
+ EXPECT_FALSE(ParseMimeTypeWithoutParameter("x-video", NULL, NULL));
+ EXPECT_FALSE(ParseMimeTypeWithoutParameter("x-video/", NULL, NULL));
+
+ EXPECT_FALSE(ParseMimeTypeWithoutParameter("application/a/b/c", NULL, NULL));
+
+ //EXPECT_TRUE(ParseMimeTypeWithoutParameter("video/mime;parameter"));
+}
+
+TEST(MimeUtilTest, TestIsValidTopLevelMimeType) {
+ EXPECT_TRUE(IsValidTopLevelMimeType("application"));
+ EXPECT_TRUE(IsValidTopLevelMimeType("audio"));
+ EXPECT_TRUE(IsValidTopLevelMimeType("example"));
+ EXPECT_TRUE(IsValidTopLevelMimeType("image"));
+ EXPECT_TRUE(IsValidTopLevelMimeType("message"));
+ EXPECT_TRUE(IsValidTopLevelMimeType("model"));
+ EXPECT_TRUE(IsValidTopLevelMimeType("multipart"));
+ EXPECT_TRUE(IsValidTopLevelMimeType("text"));
+ EXPECT_TRUE(IsValidTopLevelMimeType("video"));
+
+ EXPECT_TRUE(IsValidTopLevelMimeType("TEXT"));
+ EXPECT_TRUE(IsValidTopLevelMimeType("Text"));
+ EXPECT_TRUE(IsValidTopLevelMimeType("TeXt"));
+
+ EXPECT_FALSE(IsValidTopLevelMimeType("mime"));
+ EXPECT_FALSE(IsValidTopLevelMimeType(""));
+ EXPECT_FALSE(IsValidTopLevelMimeType("/"));
+ EXPECT_FALSE(IsValidTopLevelMimeType(" "));
+
+ EXPECT_TRUE(IsValidTopLevelMimeType("x-video"));
+ EXPECT_TRUE(IsValidTopLevelMimeType("X-video"));
+
+ EXPECT_FALSE(IsValidTopLevelMimeType("x-"));
}
TEST(MimeUtilTest, TestToIANAMediaType) {
« 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