Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "net/base/mime_sniffer.h" | 5 #include "net/base/mime_sniffer.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "url/gurl.h" | 8 #include "url/gurl.h" |
| 9 | 9 |
| 10 namespace net { | 10 namespace net { |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 SniffMimeType(kCNNRSS, std::string(), "text/xml")); | 332 SniffMimeType(kCNNRSS, std::string(), "text/xml")); |
| 333 EXPECT_EQ("text/plain", SniffMimeType(kCNNRSS, std::string(), "text/plain")); | 333 EXPECT_EQ("text/plain", SniffMimeType(kCNNRSS, std::string(), "text/plain")); |
| 334 | 334 |
| 335 // Don't sniff random XML as something different. | 335 // Don't sniff random XML as something different. |
| 336 EXPECT_EQ("text/xml", | 336 EXPECT_EQ("text/xml", |
| 337 SniffMimeType("<?xml?><notafeed", std::string(), "text/xml")); | 337 SniffMimeType("<?xml?><notafeed", std::string(), "text/xml")); |
| 338 // Don't sniff random plain-text as something different. | 338 // Don't sniff random plain-text as something different. |
| 339 EXPECT_EQ("text/plain", | 339 EXPECT_EQ("text/plain", |
| 340 SniffMimeType("<?xml?><notafeed", std::string(), "text/plain")); | 340 SniffMimeType("<?xml?><notafeed", std::string(), "text/plain")); |
| 341 | 341 |
| 342 // Positive test for the two instances we upgrade to XHTML. | 342 // We never upgrade to application/xhtml+xml. |
| 343 EXPECT_EQ("application/xhtml+xml", | 343 EXPECT_EQ("text/xml", |
| 344 SniffMimeType("<html xmlns=\"http://www.w3.org/1999/xhtml\">", | 344 SniffMimeType("<html xmlns=\"http://www.w3.org/1999/xhtml\">", |
| 345 std::string(), | 345 std::string(), "text/xml")); |
| 346 "text/xml")); | 346 EXPECT_EQ("application/xml", |
| 347 EXPECT_EQ("application/xhtml+xml", | |
| 348 SniffMimeType("<html xmlns=\"http://www.w3.org/1999/xhtml\">", | 347 SniffMimeType("<html xmlns=\"http://www.w3.org/1999/xhtml\">", |
| 349 std::string(), | 348 std::string(), "application/xml")); |
| 350 "application/xml")); | |
| 351 | |
| 352 // Following our behavior with HTML, don't call other mime types XHTML. | |
| 353 EXPECT_EQ("text/plain", | 349 EXPECT_EQ("text/plain", |
| 354 SniffMimeType("<html xmlns=\"http://www.w3.org/1999/xhtml\">", | 350 SniffMimeType("<html xmlns=\"http://www.w3.org/1999/xhtml\">", |
| 355 std::string(), | 351 std::string(), |
| 356 "text/plain")); | 352 "text/plain")); |
| 357 EXPECT_EQ("application/rss+xml", | 353 EXPECT_EQ("application/rss+xml", |
| 358 SniffMimeType("<html xmlns=\"http://www.w3.org/1999/xhtml\">", | 354 SniffMimeType("<html xmlns=\"http://www.w3.org/1999/xhtml\">", |
| 359 std::string(), | 355 std::string(), |
| 360 "application/rss+xml")); | 356 "application/rss+xml")); |
| 361 | |
| 362 // Don't sniff other HTML-looking bits as HTML. | |
| 363 EXPECT_EQ("text/xml", | 357 EXPECT_EQ("text/xml", |
| 364 SniffMimeType("<html><head>", std::string(), "text/xml")); | 358 SniffMimeType("<html><head>", std::string(), "text/xml")); |
| 365 EXPECT_EQ("text/xml", | 359 EXPECT_EQ("text/xml", |
| 366 SniffMimeType("<foo><html xmlns=\"http://www.w3.org/1999/xhtml\">", | 360 SniffMimeType("<foo><html xmlns=\"http://www.w3.org/1999/xhtml\">", |
|
mmenke
2017/05/17 20:51:42
To still be meaningful, should this be <foo><rss x
tkent
2017/05/19 00:55:42
Done.
| |
| 367 std::string(), | 361 std::string(), |
| 368 "text/xml")); | 362 "text/xml")); |
| 369 } | 363 } |
| 370 | 364 |
| 371 // Test content which is >= 1024 bytes, and includes no open angle bracket. | 365 // Test content which is >= 1024 bytes, and includes no open angle bracket. |
| 372 // http://code.google.com/p/chromium/issues/detail?id=3521 | 366 // http://code.google.com/p/chromium/issues/detail?id=3521 |
| 373 TEST(MimeSnifferTest, XMLTestLargeNoAngledBracket) { | 367 TEST(MimeSnifferTest, XMLTestLargeNoAngledBracket) { |
| 374 // Make a large input, with 1024 bytes of "x". | 368 // Make a large input, with 1024 bytes of "x". |
| 375 std::string content; | 369 std::string content; |
| 376 content.resize(1024); | 370 content.resize(1024); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 | 546 |
| 553 INSTANTIATE_TEST_CASE_P(MimeSnifferControlCodesEdgeCaseTest, | 547 INSTANTIATE_TEST_CASE_P(MimeSnifferControlCodesEdgeCaseTest, |
| 554 MimeSnifferControlCodesEdgeCaseTest, | 548 MimeSnifferControlCodesEdgeCaseTest, |
| 555 Values("\x01__", // first byte is binary | 549 Values("\x01__", // first byte is binary |
| 556 "__\x03", // last byte is binary | 550 "__\x03", // last byte is binary |
| 557 "_\x02_" // a byte in the middle is binary | 551 "_\x02_" // a byte in the middle is binary |
| 558 )); | 552 )); |
| 559 | 553 |
| 560 } // namespace | 554 } // namespace |
| 561 } // namespace net | 555 } // namespace net |
| OLD | NEW |