diff options
Diffstat (limited to 'chromium/net/base/mime_util_unittest.cc')
-rw-r--r-- | chromium/net/base/mime_util_unittest.cc | 194 |
1 files changed, 166 insertions, 28 deletions
diff --git a/chromium/net/base/mime_util_unittest.cc b/chromium/net/base/mime_util_unittest.cc index cc6f4aade7d..bb783af90f3 100644 --- a/chromium/net/base/mime_util_unittest.cc +++ b/chromium/net/base/mime_util_unittest.cc @@ -8,6 +8,10 @@ #include "net/base/mime_util.h" #include "testing/gtest/include/gtest/gtest.h" +#if defined(OS_ANDROID) +#include "base/android/build_info.h" +#endif + namespace net { TEST(MimeUtilTest, ExtensionTest) { @@ -73,9 +77,15 @@ TEST(MimeUtilTest, LookupTypes) { EXPECT_FALSE(IsSupportedNonImageMimeType("text/vcard")); EXPECT_FALSE(IsSupportedNonImageMimeType("application/virus")); EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-x509-user-cert")); + EXPECT_TRUE(IsSupportedNonImageMimeType("application/json")); + EXPECT_TRUE(IsSupportedNonImageMimeType("application/+json")); + EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-suggestions+json")); + EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-s+json;x=2")); #if defined(OS_ANDROID) EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-x509-ca-cert")); EXPECT_TRUE(IsSupportedNonImageMimeType("application/x-pkcs12")); + EXPECT_TRUE(IsSupportedMediaMimeType("application/vnd.apple.mpegurl")); + EXPECT_TRUE(IsSupportedMediaMimeType("application/x-mpegurl")); #endif EXPECT_TRUE(IsSupportedMimeType("image/jpeg")); @@ -84,6 +94,39 @@ TEST(MimeUtilTest, LookupTypes) { EXPECT_TRUE(IsSupportedMimeType("text/banana")); EXPECT_FALSE(IsSupportedMimeType("text/vcard")); EXPECT_FALSE(IsSupportedMimeType("application/virus")); + EXPECT_FALSE(IsSupportedMimeType("application/x-json")); + EXPECT_FALSE(IsSupportedNonImageMimeType("application/vnd.doc;x=y+json")); +} + +TEST(MimeUtilTest, StrictMediaMimeType) { + EXPECT_TRUE(IsStrictMediaMimeType("video/webm")); + EXPECT_TRUE(IsStrictMediaMimeType("audio/webm")); + + EXPECT_TRUE(IsStrictMediaMimeType("audio/wav")); + EXPECT_TRUE(IsStrictMediaMimeType("audio/x-wav")); + + EXPECT_TRUE(IsStrictMediaMimeType("video/ogg")); + EXPECT_TRUE(IsStrictMediaMimeType("audio/ogg")); + EXPECT_TRUE(IsStrictMediaMimeType("application/ogg")); + + EXPECT_TRUE(IsStrictMediaMimeType("audio/mpeg")); + EXPECT_TRUE(IsStrictMediaMimeType("audio/mp3")); + EXPECT_TRUE(IsStrictMediaMimeType("audio/x-mp3")); + + // TODO(amogh.bihani): These will be fixed http://crbug.com/53193 + EXPECT_FALSE(IsStrictMediaMimeType("video/mp4")); + EXPECT_FALSE(IsStrictMediaMimeType("video/x-m4v")); + EXPECT_FALSE(IsStrictMediaMimeType("audio/mp4")); + EXPECT_FALSE(IsStrictMediaMimeType("audio/x-m4a")); + + EXPECT_FALSE(IsStrictMediaMimeType("application/x-mpegurl")); + EXPECT_FALSE(IsStrictMediaMimeType("application/vnd.apple.mpegurl")); + // --------------------------------------------------------------------------- + + EXPECT_FALSE(IsStrictMediaMimeType("video/unknown")); + EXPECT_FALSE(IsStrictMediaMimeType("audio/unknown")); + EXPECT_FALSE(IsStrictMediaMimeType("application/unknown")); + EXPECT_FALSE(IsStrictMediaMimeType("unknown/unknown")); } TEST(MimeUtilTest, MatchesMimeType) { @@ -94,6 +137,8 @@ TEST(MimeUtilTest, MatchesMimeType) { EXPECT_TRUE(MatchesMimeType("application/*+xml", "application/html+xml")); EXPECT_TRUE(MatchesMimeType("application/*+xml", "application/+xml")); + EXPECT_TRUE(MatchesMimeType("application/*+json", + "application/x-myformat+json")); EXPECT_TRUE(MatchesMimeType("aaa*aaa", "aaaaaa")); EXPECT_TRUE(MatchesMimeType("*", std::string())); EXPECT_FALSE(MatchesMimeType("video/", "video/x-mpeg")); @@ -148,6 +193,60 @@ TEST(MimeUtilTest, MatchesMimeType) { EXPECT_TRUE(MatchesMimeType("ab/*cd", "ab/xxxcd")); } +TEST(MimeUtilTest, CommonMediaMimeType) { +#if defined(OS_ANDROID) + bool HLSSupported; + if (base::android::BuildInfo::GetInstance()->sdk_int() < 14) + HLSSupported = false; + else + HLSSupported = true; +#endif + + EXPECT_TRUE(IsSupportedMediaMimeType("audio/webm")); + EXPECT_TRUE(IsSupportedMediaMimeType("video/webm")); + + EXPECT_TRUE(IsSupportedMediaMimeType("audio/wav")); + EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-wav")); + + EXPECT_TRUE(IsSupportedMediaMimeType("audio/ogg")); + EXPECT_TRUE(IsSupportedMediaMimeType("application/ogg")); +#if defined(OS_ANDROID) + EXPECT_FALSE(IsSupportedMediaMimeType("video/ogg")); + EXPECT_EQ(HLSSupported, IsSupportedMediaMimeType("application/x-mpegurl")); + EXPECT_EQ(HLSSupported, + IsSupportedMediaMimeType("application/vnd.apple.mpegurl")); +#else + EXPECT_TRUE(IsSupportedMediaMimeType("video/ogg")); + EXPECT_FALSE(IsSupportedMediaMimeType("application/x-mpegurl")); + EXPECT_FALSE(IsSupportedMediaMimeType("application/vnd.apple.mpegurl")); +#endif // OS_ANDROID + +#if defined(USE_PROPRIETARY_CODECS) + EXPECT_TRUE(IsSupportedMediaMimeType("audio/mp4")); + EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-m4a")); + EXPECT_TRUE(IsSupportedMediaMimeType("video/mp4")); + EXPECT_TRUE(IsSupportedMediaMimeType("video/x-m4v")); + + EXPECT_TRUE(IsSupportedMediaMimeType("audio/mp3")); + EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-mp3")); + EXPECT_TRUE(IsSupportedMediaMimeType("audio/mpeg")); +#else + EXPECT_FALSE(IsSupportedMediaMimeType("audio/mp4")); + EXPECT_FALSE(IsSupportedMediaMimeType("audio/x-m4a")); + EXPECT_FALSE(IsSupportedMediaMimeType("video/mp4")); + EXPECT_FALSE(IsSupportedMediaMimeType("video/x-m4v")); + + EXPECT_FALSE(IsSupportedMediaMimeType("audio/mp3")); + EXPECT_FALSE(IsSupportedMediaMimeType("audio/x-mp3")); + EXPECT_FALSE(IsSupportedMediaMimeType("audio/mpeg")); +#endif // USE_PROPRIETARY_CODECS + EXPECT_FALSE(IsSupportedMediaMimeType("video/mp3")); + + EXPECT_FALSE(IsSupportedMediaMimeType("video/unknown")); + EXPECT_FALSE(IsSupportedMediaMimeType("audio/unknown")); + EXPECT_FALSE(IsSupportedMediaMimeType("unknown/unknown")); +} + // Note: codecs should only be a list of 2 or fewer; hence the restriction of // results' length to 2. TEST(MimeUtilTest, ParseCodecString) { @@ -184,38 +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(WideToUTF8(std::wstring(L"\u2603"))); + 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("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) { @@ -267,7 +405,7 @@ TEST(MimeUtilTest, TestGetExtensionsForMimeType) { bool found = false; for (size_t j = 0; !found && j < extensions.size(); ++j) { #if defined(OS_WIN) - if (extensions[j] == UTF8ToWide(tests[i].contained_result)) + if (extensions[j] == base::UTF8ToWide(tests[i].contained_result)) found = true; #else if (extensions[j] == tests[i].contained_result) |