| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 "", "application/octet-stream" }, | 78 "", "application/octet-stream" }, |
| 79 { "%!PS-Adobe-3.0", sizeof("%!PS-Adobe-3.0")-1, | 79 { "%!PS-Adobe-3.0", sizeof("%!PS-Adobe-3.0")-1, |
| 80 "http://www.example.com/foo", | 80 "http://www.example.com/foo", |
| 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", "application/octet-stream" }, | 84 "application/octet-stream", "application/octet-stream" }, |
| 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 { "RIFF\xd4\x32\0\0WEBPVP8 ", sizeof("RIFF\xd4\x32\0\0WEBPVP8 ")-1, |
| 89 "http://www.example.com/foo", |
| 90 "text/plain", "image/webp" }, |
| 88 }; | 91 }; |
| 89 | 92 |
| 90 TestArray(tests, arraysize(tests)); | 93 TestArray(tests, arraysize(tests)); |
| 91 } | 94 } |
| 92 | 95 |
| 93 TEST(MimeSnifferTest, ChromeExtensionsTest) { | 96 TEST(MimeSnifferTest, ChromeExtensionsTest) { |
| 94 SnifferTest tests[] = { | 97 SnifferTest tests[] = { |
| 95 // schemes | 98 // schemes |
| 96 { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1, | 99 { "Cr24\x02\x00\x00\x00", sizeof("Cr24\x02\x00\x00\x00")-1, |
| 97 "http://www.example.com/foo.crx", | 100 "http://www.example.com/foo.crx", |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 content.resize(1024); | 388 content.resize(1024); |
| 386 std::fill(content.begin(), content.end(), 'x'); | 389 std::fill(content.begin(), content.end(), 'x'); |
| 387 content[1000] = 0x01; | 390 content[1000] = 0x01; |
| 388 | 391 |
| 389 // content.size() >= 1024 so the sniff is unambiguous. | 392 // content.size() >= 1024 so the sniff is unambiguous. |
| 390 std::string mime_type; | 393 std::string mime_type; |
| 391 EXPECT_TRUE(net::SniffMimeType(content.data(), content.size(), GURL(), | 394 EXPECT_TRUE(net::SniffMimeType(content.data(), content.size(), GURL(), |
| 392 "text/plain", &mime_type)); | 395 "text/plain", &mime_type)); |
| 393 EXPECT_EQ("application/octet-stream", mime_type); | 396 EXPECT_EQ("application/octet-stream", mime_type); |
| 394 } | 397 } |
| OLD | NEW |