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

Unified Diff: net/base/mime_sniffer_unittest.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
Index: net/base/mime_sniffer_unittest.cc
diff --git a/net/base/mime_sniffer_unittest.cc b/net/base/mime_sniffer_unittest.cc
index e4f2d5cf3a08cb6f5c5b7d27bad123a834345303..7b27175bfc6e8ec44a99a54a4d4bc15dc1a415ca 100644
--- a/net/base/mime_sniffer_unittest.cc
+++ b/net/base/mime_sniffer_unittest.cc
@@ -22,10 +22,10 @@ static void TestArray(SnifferTest* tests, size_t count) {
for (size_t i = 0; i < count; ++i) {
SniffMimeType(tests[i].content,
- tests[i].content_len,
- GURL(tests[i].url),
- tests[i].type_hint,
- &mime_type);
+ tests[i].content_len,
+ GURL(tests[i].url),
+ tests[i].type_hint,
+ &mime_type);
EXPECT_EQ(tests[i].mime_type, mime_type);
}
}
@@ -36,8 +36,8 @@ static std::string SniffMimeType(const std::string& content,
const std::string& url,
const std::string& mime_type_hint) {
std::string mime_type;
- SniffMimeType(content.data(), content.size(), GURL(url),
- mime_type_hint, &mime_type);
+ SniffMimeType(
+ content.data(), content.size(), GURL(url), mime_type_hint, &mime_type);
return mime_type;
}
@@ -45,9 +45,7 @@ TEST(MimeSnifferTest, BoundaryConditionsTest) {
std::string mime_type;
std::string type_hint;
- char buf[] = {
- 'd', '\x1f', '\xFF'
- };
+ char buf[] = {'d', '\x1f', '\xFF'};
GURL url;
@@ -61,27 +59,28 @@ TEST(MimeSnifferTest, BoundaryConditionsTest) {
TEST(MimeSnifferTest, BasicSniffingTest) {
SnifferTest tests[] = {
- { "<!DOCTYPE html PUBLIC", sizeof("<!DOCTYPE html PUBLIC")-1,
- "http://www.example.com/",
- "", "text/html" },
- { "<HtMl><Body></body></htMl>", sizeof("<HtMl><Body></body></htMl>")-1,
- "http://www.example.com/foo.gif",
- "application/octet-stream", "application/octet-stream" },
- { "GIF89a\x1F\x83\x94", sizeof("GIF89a\xAF\x83\x94")-1,
- "http://www.example.com/foo",
- "text/plain", "image/gif" },
- { "Gif87a\x1F\x83\x94", sizeof("Gif87a\xAF\x83\x94")-1,
- "http://www.example.com/foo?param=tt.gif",
- "", "application/octet-stream" },
- { "%!PS-Adobe-3.0", sizeof("%!PS-Adobe-3.0")-1,
- "http://www.example.com/foo",
- "text/plain", "text/plain" },
- { "\x89" "PNG\x0D\x0A\x1A\x0A", sizeof("\x89" "PNG\x0D\x0A\x1A\x0A")-1,
- "http://www.example.com/foo",
- "application/octet-stream", "application/octet-stream" },
- { "\xFF\xD8\xFF\x23\x49\xAF", sizeof("\xFF\xD8\xFF\x23\x49\xAF")-1,
- "http://www.example.com/foo",
- "", "image/jpeg" },
+ {"<!DOCTYPE html PUBLIC", sizeof("<!DOCTYPE html PUBLIC") - 1,
+ "http://www.example.com/", "", "text/html"},
+ {"<HtMl><Body></body></htMl>", sizeof("<HtMl><Body></body></htMl>") - 1,
+ "http://www.example.com/foo.gif", "application/octet-stream",
+ "application/octet-stream"},
+ {"GIF89a\x1F\x83\x94", sizeof("GIF89a\xAF\x83\x94") - 1,
+ "http://www.example.com/foo", "text/plain", "image/gif"},
+ {"Gif87a\x1F\x83\x94", sizeof("Gif87a\xAF\x83\x94") - 1,
+ "http://www.example.com/foo?param=tt.gif", "",
+ "application/octet-stream"},
+ {"%!PS-Adobe-3.0", sizeof("%!PS-Adobe-3.0") - 1,
+ "http://www.example.com/foo", "text/plain", "text/plain"},
+ {"\x89"
+ "PNG\x0D\x0A\x1A\x0A",
+ sizeof(
+ "\x89"
+ "PNG\x0D\x0A\x1A\x0A") -
+ 1,
+ "http://www.example.com/foo", "application/octet-stream",
+ "application/octet-stream"},
+ {"\xFF\xD8\xFF\x23\x49\xAF", sizeof("\xFF\xD8\xFF\x23\x49\xAF") - 1,
+ "http://www.example.com/foo", "", "image/jpeg"},
};
TestArray(tests, arraysize(tests));
@@ -89,66 +88,53 @@ TEST(MimeSnifferTest, BasicSniffingTest) {
TEST(MimeSnifferTest, ChromeExtensionsTest) {
SnifferTest tests[] = {
- // schemes
- { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
- "http://www.example.com/foo.crx",
- "", "application/x-chrome-extension" },
- { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
- "https://www.example.com/foo.crx",
- "", "application/x-chrome-extension" },
- { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
- "ftp://www.example.com/foo.crx",
- "", "application/x-chrome-extension" },
-
- // some other mimetypes that should get converted
- { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
- "http://www.example.com/foo.crx",
- "text/plain", "application/x-chrome-extension" },
- { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
- "http://www.example.com/foo.crx",
- "application/octet-stream", "application/x-chrome-extension" },
-
- // success edge cases
- { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
- "http://www.example.com/foo.crx?query=string",
- "", "application/x-chrome-extension" },
- { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
- "http://www.example.com/foo..crx",
- "", "application/x-chrome-extension" },
-
- // wrong file extension
- { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
- "http://www.example.com/foo.bin",
- "", "application/octet-stream" },
- { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
- "http://www.example.com/foo.bin?monkey",
- "", "application/octet-stream" },
- { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
- "invalid-url",
- "", "application/octet-stream" },
- { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
- "http://www.example.com",
- "", "application/octet-stream" },
- { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
- "http://www.example.com/",
- "", "application/octet-stream" },
- { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
- "http://www.example.com/foo",
- "", "application/octet-stream" },
- { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
- "http://www.example.com/foocrx",
- "", "application/octet-stream" },
- { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
- "http://www.example.com/foo.crx.blech",
- "", "application/octet-stream" },
-
- // wrong magic
- { "Cr24\x02\x00\x00\x01", sizeof("Cr24\x02\x00\x00\x01")-1,
- "http://www.example.com/foo.crx?monkey",
- "", "application/octet-stream" },
- { "PADDING_Cr24\x02\x00\x00\x00", sizeof("PADDING_Cr24\x02\x00\x00\x00")-1,
- "http://www.example.com/foo.crx?monkey",
- "", "application/octet-stream" },
+ // schemes
+ {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
+ "http://www.example.com/foo.crx", "", "application/x-chrome-extension"},
+ {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
+ "https://www.example.com/foo.crx", "", "application/x-chrome-extension"},
+ {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
+ "ftp://www.example.com/foo.crx", "", "application/x-chrome-extension"},
+
+ // some other mimetypes that should get converted
+ {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
+ "http://www.example.com/foo.crx", "text/plain",
+ "application/x-chrome-extension"},
+ {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
+ "http://www.example.com/foo.crx", "application/octet-stream",
+ "application/x-chrome-extension"},
+
+ // success edge cases
+ {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
+ "http://www.example.com/foo.crx?query=string", "",
+ "application/x-chrome-extension"},
+ {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
+ "http://www.example.com/foo..crx", "", "application/x-chrome-extension"},
+
+ // wrong file extension
+ {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
+ "http://www.example.com/foo.bin", "", "application/octet-stream"},
+ {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
+ "http://www.example.com/foo.bin?monkey", "", "application/octet-stream"},
+ {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
+ "invalid-url", "", "application/octet-stream"},
+ {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
+ "http://www.example.com", "", "application/octet-stream"},
+ {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
+ "http://www.example.com/", "", "application/octet-stream"},
+ {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
+ "http://www.example.com/foo", "", "application/octet-stream"},
+ {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
+ "http://www.example.com/foocrx", "", "application/octet-stream"},
+ {"Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00") - 1,
+ "http://www.example.com/foo.crx.blech", "", "application/octet-stream"},
+
+ // wrong magic
+ {"Cr24\x02\x00\x00\x01", sizeof("Cr24\x02\x00\x00\x01") - 1,
+ "http://www.example.com/foo.crx?monkey", "", "application/octet-stream"},
+ {"PADDING_Cr24\x02\x00\x00\x00",
+ sizeof("PADDING_Cr24\x02\x00\x00\x00") - 1,
+ "http://www.example.com/foo.crx?monkey", "", "application/octet-stream"},
};
TestArray(tests, arraysize(tests));
@@ -156,33 +142,26 @@ TEST(MimeSnifferTest, ChromeExtensionsTest) {
TEST(MimeSnifferTest, MozillaCompatibleTest) {
SnifferTest tests[] = {
- { " \n <hTmL>\n <hea", sizeof(" \n <hTmL>\n <hea")-1,
- "http://www.example.com/",
- "", "text/html" },
- { " \n <hTmL>\n <hea", sizeof(" \n <hTmL>\n <hea")-1,
- "http://www.example.com/",
- "text/plain", "text/plain" },
- { "BMjlakdsfk", sizeof("BMjlakdsfk")-1,
- "http://www.example.com/foo",
- "", "image/bmp" },
- { "\x00\x00\x30\x00", sizeof("\x00\x00\x30\x00")-1,
- "http://www.example.com/favicon.ico",
- "", "application/octet-stream" },
- { "#!/bin/sh\nls /\n", sizeof("#!/bin/sh\nls /\n")-1,
- "http://www.example.com/foo",
- "", "text/plain" },
- { "From: Fred\nTo: Bob\n\nHi\n.\n",
- sizeof("From: Fred\nTo: Bob\n\nHi\n.\n")-1,
- "http://www.example.com/foo",
- "", "text/plain" },
- { "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
- sizeof("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")-1,
- "http://www.example.com/foo",
- "", "text/xml" },
- { "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
- sizeof("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")-1,
- "http://www.example.com/foo",
- "application/octet-stream", "application/octet-stream" },
+ {" \n <hTmL>\n <hea", sizeof(" \n <hTmL>\n <hea") - 1,
+ "http://www.example.com/", "", "text/html"},
+ {" \n <hTmL>\n <hea", sizeof(" \n <hTmL>\n <hea") - 1,
+ "http://www.example.com/", "text/plain", "text/plain"},
+ {"BMjlakdsfk", sizeof("BMjlakdsfk") - 1, "http://www.example.com/foo", "",
+ "image/bmp"},
+ {"\x00\x00\x30\x00", sizeof("\x00\x00\x30\x00") - 1,
+ "http://www.example.com/favicon.ico", "", "application/octet-stream"},
+ {"#!/bin/sh\nls /\n", sizeof("#!/bin/sh\nls /\n") - 1,
+ "http://www.example.com/foo", "", "text/plain"},
+ {"From: Fred\nTo: Bob\n\nHi\n.\n",
+ sizeof("From: Fred\nTo: Bob\n\nHi\n.\n") - 1,
+ "http://www.example.com/foo", "", "text/plain"},
+ {"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
+ sizeof("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") - 1,
+ "http://www.example.com/foo", "", "text/xml"},
+ {"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
+ sizeof("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") - 1,
+ "http://www.example.com/foo", "application/octet-stream",
+ "application/octet-stream"},
};
TestArray(tests, arraysize(tests));
@@ -190,62 +169,69 @@ TEST(MimeSnifferTest, MozillaCompatibleTest) {
TEST(MimeSnifferTest, DontAllowPrivilegeEscalationTest) {
SnifferTest tests[] = {
- { "GIF87a\n<html>\n<body>"
- "<script>alert('haxorzed');\n</script>"
- "</body></html>\n",
- sizeof("GIF87a\n<html>\n<body>"
- "<script>alert('haxorzed');\n</script>"
- "</body></html>\n")-1,
- "http://www.example.com/foo",
- "", "image/gif" },
- { "GIF87a\n<html>\n<body>"
- "<script>alert('haxorzed');\n</script>"
- "</body></html>\n",
- sizeof("GIF87a\n<html>\n<body>"
- "<script>alert('haxorzed');\n</script>"
- "</body></html>\n")-1,
- "http://www.example.com/foo?q=ttt.html",
- "", "image/gif" },
- { "GIF87a\n<html>\n<body>"
- "<script>alert('haxorzed');\n</script>"
- "</body></html>\n",
- sizeof("GIF87a\n<html>\n<body>"
- "<script>alert('haxorzed');\n</script>"
- "</body></html>\n")-1,
- "http://www.example.com/foo#ttt.html",
- "", "image/gif" },
- { "a\n<html>\n<body>"
- "<script>alert('haxorzed');\n</script>"
- "</body></html>\n",
- sizeof("a\n<html>\n<body>"
- "<script>alert('haxorzed');\n</script>"
- "</body></html>\n")-1,
- "http://www.example.com/foo",
- "", "text/plain" },
- { "a\n<html>\n<body>"
- "<script>alert('haxorzed');\n</script>"
- "</body></html>\n",
- sizeof("a\n<html>\n<body>"
- "<script>alert('haxorzed');\n</script>"
- "</body></html>\n")-1,
- "http://www.example.com/foo?q=ttt.html",
- "", "text/plain" },
- { "a\n<html>\n<body>"
- "<script>alert('haxorzed');\n</script>"
- "</body></html>\n",
- sizeof("a\n<html>\n<body>"
- "<script>alert('haxorzed');\n</script>"
- "</body></html>\n")-1,
- "http://www.example.com/foo#ttt.html",
- "", "text/plain" },
- { "a\n<html>\n<body>"
- "<script>alert('haxorzed');\n</script>"
- "</body></html>\n",
- sizeof("a\n<html>\n<body>"
- "<script>alert('haxorzed');\n</script>"
- "</body></html>\n")-1,
- "http://www.example.com/foo.html",
- "", "text/plain" },
+ {"GIF87a\n<html>\n<body>"
+ "<script>alert('haxorzed');\n</script>"
+ "</body></html>\n",
+ sizeof(
+ "GIF87a\n<html>\n<body>"
+ "<script>alert('haxorzed');\n</script>"
+ "</body></html>\n") -
+ 1,
+ "http://www.example.com/foo", "", "image/gif"},
+ {"GIF87a\n<html>\n<body>"
+ "<script>alert('haxorzed');\n</script>"
+ "</body></html>\n",
+ sizeof(
+ "GIF87a\n<html>\n<body>"
+ "<script>alert('haxorzed');\n</script>"
+ "</body></html>\n") -
+ 1,
+ "http://www.example.com/foo?q=ttt.html", "", "image/gif"},
+ {"GIF87a\n<html>\n<body>"
+ "<script>alert('haxorzed');\n</script>"
+ "</body></html>\n",
+ sizeof(
+ "GIF87a\n<html>\n<body>"
+ "<script>alert('haxorzed');\n</script>"
+ "</body></html>\n") -
+ 1,
+ "http://www.example.com/foo#ttt.html", "", "image/gif"},
+ {"a\n<html>\n<body>"
+ "<script>alert('haxorzed');\n</script>"
+ "</body></html>\n",
+ sizeof(
+ "a\n<html>\n<body>"
+ "<script>alert('haxorzed');\n</script>"
+ "</body></html>\n") -
+ 1,
+ "http://www.example.com/foo", "", "text/plain"},
+ {"a\n<html>\n<body>"
+ "<script>alert('haxorzed');\n</script>"
+ "</body></html>\n",
+ sizeof(
+ "a\n<html>\n<body>"
+ "<script>alert('haxorzed');\n</script>"
+ "</body></html>\n") -
+ 1,
+ "http://www.example.com/foo?q=ttt.html", "", "text/plain"},
+ {"a\n<html>\n<body>"
+ "<script>alert('haxorzed');\n</script>"
+ "</body></html>\n",
+ sizeof(
+ "a\n<html>\n<body>"
+ "<script>alert('haxorzed');\n</script>"
+ "</body></html>\n") -
+ 1,
+ "http://www.example.com/foo#ttt.html", "", "text/plain"},
+ {"a\n<html>\n<body>"
+ "<script>alert('haxorzed');\n</script>"
+ "</body></html>\n",
+ sizeof(
+ "a\n<html>\n<body>"
+ "<script>alert('haxorzed');\n</script>"
+ "</body></html>\n") -
+ 1,
mmenke 2014/10/10 18:12:39 Confusing indentation here, methinks.
+ "http://www.example.com/foo.html", "", "text/plain"},
};
TestArray(tests, arraysize(tests));
@@ -253,21 +239,22 @@ TEST(MimeSnifferTest, DontAllowPrivilegeEscalationTest) {
TEST(MimeSnifferTest, UnicodeTest) {
SnifferTest tests[] = {
- { "\xEF\xBB\xBF" "Hi there", sizeof("\xEF\xBB\xBF" "Hi there")-1,
- "http://www.example.com/foo",
- "", "text/plain" },
- { "\xEF\xBB\xBF\xED\x7A\xAD\x7A\x0D\x79",
- sizeof("\xEF\xBB\xBF\xED\x7A\xAD\x7A\x0D\x79")-1,
- "http://www.example.com/foo",
- "", "text/plain" },
- { "\xFE\xFF\xD0\xA5\xD0\xBE\xD0\xBB\xD1\x83\xD0\xB9",
- sizeof("\xFE\xFF\xD0\xA5\xD0\xBE\xD0\xBB\xD1\x83\xD0\xB9")-1,
- "http://www.example.com/foo",
- "", "text/plain" },
- { "\xFE\xFF\x00\x41\x00\x20\xD8\x00\xDC\x00\xD8\x00\xDC\x01",
- sizeof("\xFE\xFF\x00\x41\x00\x20\xD8\x00\xDC\x00\xD8\x00\xDC\x01")-1,
- "http://www.example.com/foo",
- "", "text/plain" },
+ {"\xEF\xBB\xBF"
+ "Hi there",
+ sizeof(
+ "\xEF\xBB\xBF"
+ "Hi there") -
+ 1,
+ "http://www.example.com/foo", "", "text/plain"},
+ {"\xEF\xBB\xBF\xED\x7A\xAD\x7A\x0D\x79",
+ sizeof("\xEF\xBB\xBF\xED\x7A\xAD\x7A\x0D\x79") - 1,
+ "http://www.example.com/foo", "", "text/plain"},
+ {"\xFE\xFF\xD0\xA5\xD0\xBE\xD0\xBB\xD1\x83\xD0\xB9",
+ sizeof("\xFE\xFF\xD0\xA5\xD0\xBE\xD0\xBB\xD1\x83\xD0\xB9") - 1,
+ "http://www.example.com/foo", "", "text/plain"},
+ {"\xFE\xFF\x00\x41\x00\x20\xD8\x00\xDC\x00\xD8\x00\xDC\x01",
+ sizeof("\xFE\xFF\x00\x41\x00\x20\xD8\x00\xDC\x00\xD8\x00\xDC\x01") - 1,
+ "http://www.example.com/foo", "", "text/plain"},
};
TestArray(tests, arraysize(tests));
@@ -275,27 +262,22 @@ TEST(MimeSnifferTest, UnicodeTest) {
TEST(MimeSnifferTest, FlashTest) {
SnifferTest tests[] = {
- { "CWSdd\x00\xB3", sizeof("CWSdd\x00\xB3")-1,
- "http://www.example.com/foo",
- "", "application/octet-stream" },
- { "FLVjdkl*(#)0sdj\x00", sizeof("FLVjdkl*(#)0sdj\x00")-1,
- "http://www.example.com/foo?q=ttt.swf",
- "", "application/octet-stream" },
- { "FWS3$9\r\b\x00", sizeof("FWS3$9\r\b\x00")-1,
- "http://www.example.com/foo#ttt.swf",
- "", "application/octet-stream" },
- { "FLVjdkl*(#)0sdj", sizeof("FLVjdkl*(#)0sdj")-1,
- "http://www.example.com/foo.swf",
- "", "text/plain" },
- { "FLVjdkl*(#)0s\x01dj", sizeof("FLVjdkl*(#)0s\x01dj")-1,
- "http://www.example.com/foo/bar.swf",
- "", "application/octet-stream" },
- { "FWS3$9\r\b\x1A", sizeof("FWS3$9\r\b\x1A")-1,
- "http://www.example.com/foo.swf?clickTAG=http://www.adnetwork.com/bar",
- "", "application/octet-stream" },
- { "FWS3$9\r\x1C\b", sizeof("FWS3$9\r\x1C\b")-1,
- "http://www.example.com/foo.swf?clickTAG=http://www.adnetwork.com/bar",
- "text/plain", "application/octet-stream" },
+ {"CWSdd\x00\xB3", sizeof("CWSdd\x00\xB3") - 1,
+ "http://www.example.com/foo", "", "application/octet-stream"},
+ {"FLVjdkl*(#)0sdj\x00", sizeof("FLVjdkl*(#)0sdj\x00") - 1,
+ "http://www.example.com/foo?q=ttt.swf", "", "application/octet-stream"},
+ {"FWS3$9\r\b\x00", sizeof("FWS3$9\r\b\x00") - 1,
+ "http://www.example.com/foo#ttt.swf", "", "application/octet-stream"},
+ {"FLVjdkl*(#)0sdj", sizeof("FLVjdkl*(#)0sdj") - 1,
+ "http://www.example.com/foo.swf", "", "text/plain"},
+ {"FLVjdkl*(#)0s\x01dj", sizeof("FLVjdkl*(#)0s\x01dj") - 1,
+ "http://www.example.com/foo/bar.swf", "", "application/octet-stream"},
+ {"FWS3$9\r\b\x1A", sizeof("FWS3$9\r\b\x1A") - 1,
+ "http://www.example.com/foo.swf?clickTAG=http://www.adnetwork.com/bar",
+ "", "application/octet-stream"},
+ {"FWS3$9\r\x1C\b", sizeof("FWS3$9\r\x1C\b") - 1,
+ "http://www.example.com/foo.swf?clickTAG=http://www.adnetwork.com/bar",
+ "text/plain", "application/octet-stream"},
};
TestArray(tests, arraysize(tests));
@@ -373,8 +355,8 @@ TEST(MimeSnifferTest, XMLTestLargeNoAngledBracket) {
// content.size() >= 1024 so the sniff is unambiguous.
std::string mime_type;
- EXPECT_TRUE(SniffMimeType(content.data(), content.size(), GURL(),
- "text/xml", &mime_type));
+ EXPECT_TRUE(SniffMimeType(
+ content.data(), content.size(), GURL(), "text/xml", &mime_type));
EXPECT_EQ("text/xml", mime_type);
}
@@ -389,57 +371,71 @@ TEST(MimeSnifferTest, LooksBinary) {
// content.size() >= 1024 so the sniff is unambiguous.
std::string mime_type;
- EXPECT_TRUE(SniffMimeType(content.data(), content.size(), GURL(),
- "text/plain", &mime_type));
+ EXPECT_TRUE(SniffMimeType(
+ content.data(), content.size(), GURL(), "text/plain", &mime_type));
EXPECT_EQ("application/octet-stream", mime_type);
}
TEST(MimeSnifferTest, OfficeTest) {
SnifferTest tests[] = {
- // Check for URLs incorrectly reported as Microsoft Office files.
- { "Hi there",
- sizeof("Hi there")-1,
- "http://www.example.com/foo.doc",
- "application/msword", "application/octet-stream" },
- { "Hi there",
- sizeof("Hi there")-1,
- "http://www.example.com/foo.xls",
- "application/vnd.ms-excel", "application/octet-stream" },
- { "Hi there",
- sizeof("Hi there")-1,
- "http://www.example.com/foo.ppt",
- "application/vnd.ms-powerpoint", "application/octet-stream" },
- // Check for Microsoft Office files incorrectly reported as text.
- { "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" "Hi there",
- sizeof("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" "Hi there")-1,
- "http://www.example.com/foo.doc",
- "text/plain", "application/msword" },
- { "PK\x03\x04" "Hi there",
- sizeof("PK\x03\x04" "Hi there")-1,
- "http://www.example.com/foo.doc",
- "text/plain",
- "application/vnd.openxmlformats-officedocument."
- "wordprocessingml.document" },
- { "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" "Hi there",
- sizeof("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" "Hi there")-1,
- "http://www.example.com/foo.xls",
- "text/plain", "application/vnd.ms-excel" },
- { "PK\x03\x04" "Hi there",
- sizeof("PK\x03\x04" "Hi there")-1,
- "http://www.example.com/foo.xls",
- "text/plain",
- "application/vnd.openxmlformats-officedocument."
- "spreadsheetml.sheet" },
- { "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" "Hi there",
- sizeof("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" "Hi there")-1,
- "http://www.example.com/foo.ppt",
- "text/plain", "application/vnd.ms-powerpoint" },
- { "PK\x03\x04" "Hi there",
- sizeof("PK\x03\x04" "Hi there")-1,
- "http://www.example.com/foo.ppt",
- "text/plain",
- "application/vnd.openxmlformats-officedocument."
- "presentationml.presentation" },
+ // Check for URLs incorrectly reported as Microsoft Office files.
+ {"Hi there", sizeof("Hi there") - 1, "http://www.example.com/foo.doc",
+ "application/msword", "application/octet-stream"},
+ {"Hi there", sizeof("Hi there") - 1, "http://www.example.com/foo.xls",
+ "application/vnd.ms-excel", "application/octet-stream"},
+ {"Hi there", sizeof("Hi there") - 1, "http://www.example.com/foo.ppt",
+ "application/vnd.ms-powerpoint", "application/octet-stream"},
+ // Check for Microsoft Office files incorrectly reported as text.
+ {"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"
+ "Hi there",
+ sizeof(
+ "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"
+ "Hi there") -
+ 1,
+ "http://www.example.com/foo.doc", "text/plain", "application/msword"},
+ {"PK\x03\x04"
+ "Hi there",
+ sizeof(
+ "PK\x03\x04"
+ "Hi there") -
+ 1,
+ "http://www.example.com/foo.doc", "text/plain",
+ "application/vnd.openxmlformats-officedocument."
+ "wordprocessingml.document"},
+ {"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"
+ "Hi there",
+ sizeof(
+ "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"
+ "Hi there") -
+ 1,
+ "http://www.example.com/foo.xls", "text/plain",
+ "application/vnd.ms-excel"},
+ {"PK\x03\x04"
+ "Hi there",
+ sizeof(
+ "PK\x03\x04"
+ "Hi there") -
+ 1,
mmenke 2014/10/10 18:12:39 Line split completely not needed.
+ "http://www.example.com/foo.xls", "text/plain",
+ "application/vnd.openxmlformats-officedocument."
+ "spreadsheetml.sheet"},
+ {"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"
+ "Hi there",
+ sizeof(
+ "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"
+ "Hi there") -
+ 1,
+ "http://www.example.com/foo.ppt", "text/plain",
+ "application/vnd.ms-powerpoint"},
+ {"PK\x03\x04"
+ "Hi there",
+ sizeof(
+ "PK\x03\x04"
+ "Hi there") -
+ 1,
+ "http://www.example.com/foo.ppt", "text/plain",
+ "application/vnd.openxmlformats-officedocument."
+ "presentationml.presentation"},
};
TestArray(tests, arraysize(tests));
@@ -451,17 +447,15 @@ TEST(MimeSnifferTest, AudioVideoTest) {
std::string mime_type;
const char kFlacTestData[] =
"fLaC\x00\x00\x00\x22\x12\x00\x12\x00\x00\x00\x00\x00";
- EXPECT_TRUE(SniffMimeTypeFromLocalData(kFlacTestData,
- sizeof(kFlacTestData),
- &mime_type));
+ EXPECT_TRUE(SniffMimeTypeFromLocalData(
+ kFlacTestData, sizeof(kFlacTestData), &mime_type));
EXPECT_EQ("audio/x-flac", mime_type);
mime_type.clear();
const char kWMATestData[] =
"\x30\x26\xb2\x75\x8e\x66\xcf\x11\xa6\xd9\x00\xaa\x00\x62\xce\x6c";
- EXPECT_TRUE(SniffMimeTypeFromLocalData(kWMATestData,
- sizeof(kWMATestData),
- &mime_type));
+ EXPECT_TRUE(SniffMimeTypeFromLocalData(
+ kWMATestData, sizeof(kWMATestData), &mime_type));
EXPECT_EQ("video/x-ms-asf", mime_type);
mime_type.clear();
@@ -469,17 +463,15 @@ TEST(MimeSnifferTest, AudioVideoTest) {
// format.
const char kMP4TestData[] =
"\x00\x00\x00\x20\x66\x74\x79\x70\x4d\x34\x41\x20\x00\x00\x00\x00";
- EXPECT_TRUE(SniffMimeTypeFromLocalData(kMP4TestData,
- sizeof(kMP4TestData),
- &mime_type));
+ EXPECT_TRUE(SniffMimeTypeFromLocalData(
+ kMP4TestData, sizeof(kMP4TestData), &mime_type));
EXPECT_EQ("video/mp4", mime_type);
mime_type.clear();
const char kAACTestData[] =
"\xff\xf1\x50\x80\x02\x20\xb0\x23\x0a\x83\x20\x7d\x61\x90\x3e\xb1";
- EXPECT_TRUE(SniffMimeTypeFromLocalData(kAACTestData,
- sizeof(kAACTestData),
- &mime_type));
+ EXPECT_TRUE(SniffMimeTypeFromLocalData(
+ kAACTestData, sizeof(kAACTestData), &mime_type));
EXPECT_EQ("audio/mpeg", mime_type);
mime_type.clear();
}

Powered by Google App Engine
This is Rietveld 408576698