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

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

Issue 465048: net: Ignore the magic number sniffer if it determines an application/octet-st... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: with additional comment Created 11 years 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_sniffer.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "googleurl/src/gurl.h" 6 #include "googleurl/src/gurl.h"
7 #include "net/base/mime_sniffer.h" 7 #include "net/base/mime_sniffer.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace { 10 namespace {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 "text/plain", "text/plain" }, 81 "text/plain", "text/plain" },
82 { "\x89" "PNG\x0D\x0A\x1A\x0A", sizeof("\x89" "PNG\x0D\x0A\x1A\x0A")-1, 82 { "\x89" "PNG\x0D\x0A\x1A\x0A", sizeof("\x89" "PNG\x0D\x0A\x1A\x0A")-1,
83 "http://www.example.com/foo", 83 "http://www.example.com/foo",
84 "application/octet-stream", "image/png" }, 84 "application/octet-stream", "image/png" },
85 { "\xFF\xD8\xFF\x23\x49\xAF", sizeof("\xFF\xD8\xFF\x23\x49\xAF")-1, 85 { "\xFF\xD8\xFF\x23\x49\xAF", sizeof("\xFF\xD8\xFF\x23\x49\xAF")-1,
86 "http://www.example.com/foo", 86 "http://www.example.com/foo",
87 "", "image/jpeg" }, 87 "", "image/jpeg" },
88 }; 88 };
89 89
90 TestArray(tests, arraysize(tests)); 90 TestArray(tests, arraysize(tests));
91
92 // Don't sniff Linux installers with embedded shell scripts as text/plain.
93 std::string content = "#!/bin/bash\necho hi\n";
94 content.resize(5000, '\n');
95 content.resize(20000, '\xFD');
96 EXPECT_EQ("application/octet-stream",
97 SniffMimeType(content, "http://www.example.com/foo.bin",
98 "application/octet-stream"));
91 } 99 }
92 100
93 TEST(MimeSnifferTest, ChromeExtensionsTest) { 101 TEST(MimeSnifferTest, ChromeExtensionsTest) {
94 SnifferTest tests[] = { 102 SnifferTest tests[] = {
95 // schemes 103 // schemes
96 { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1, 104 { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
97 "http://www.example.com/foo.crx", 105 "http://www.example.com/foo.crx",
98 "", "application/x-chrome-extension" }, 106 "", "application/x-chrome-extension" },
99 { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1, 107 { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1,
100 "https://www.example.com/foo.crx", 108 "https://www.example.com/foo.crx",
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 // Make a large input, with 600 bytes of "x". 373 // Make a large input, with 600 bytes of "x".
366 std::string content; 374 std::string content;
367 content.resize(600); 375 content.resize(600);
368 std::fill(content.begin(), content.end(), 'x'); 376 std::fill(content.begin(), content.end(), 'x');
369 377
370 // content.size() >= kMaxBytesToSniff (512) so the sniff is unambiguous. 378 // content.size() >= kMaxBytesToSniff (512) so the sniff is unambiguous.
371 std::string mime_type; 379 std::string mime_type;
372 EXPECT_TRUE(net::SniffMimeType(content.data(), content.size(), GURL(), 380 EXPECT_TRUE(net::SniffMimeType(content.data(), content.size(), GURL(),
373 "text/xml", &mime_type)); 381 "text/xml", &mime_type));
374 } 382 }
OLDNEW
« no previous file with comments | « net/base/mime_sniffer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698