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><rss " |
367 std::string(), | 361 "xmlns:feedburner=\"http://rssnamespace.org/" |
368 "text/xml")); | 362 "feedburner/ext/1.0\" version=\"2.0\">", |
| 363 std::string(), "text/xml")); |
369 } | 364 } |
370 | 365 |
371 // Test content which is >= 1024 bytes, and includes no open angle bracket. | 366 // Test content which is >= 1024 bytes, and includes no open angle bracket. |
372 // http://code.google.com/p/chromium/issues/detail?id=3521 | 367 // http://code.google.com/p/chromium/issues/detail?id=3521 |
373 TEST(MimeSnifferTest, XMLTestLargeNoAngledBracket) { | 368 TEST(MimeSnifferTest, XMLTestLargeNoAngledBracket) { |
374 // Make a large input, with 1024 bytes of "x". | 369 // Make a large input, with 1024 bytes of "x". |
375 std::string content; | 370 std::string content; |
376 content.resize(1024); | 371 content.resize(1024); |
377 std::fill(content.begin(), content.end(), 'x'); | 372 std::fill(content.begin(), content.end(), 'x'); |
378 | 373 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 | 547 |
553 INSTANTIATE_TEST_CASE_P(MimeSnifferControlCodesEdgeCaseTest, | 548 INSTANTIATE_TEST_CASE_P(MimeSnifferControlCodesEdgeCaseTest, |
554 MimeSnifferControlCodesEdgeCaseTest, | 549 MimeSnifferControlCodesEdgeCaseTest, |
555 Values("\x01__", // first byte is binary | 550 Values("\x01__", // first byte is binary |
556 "__\x03", // last byte is binary | 551 "__\x03", // last byte is binary |
557 "_\x02_" // a byte in the middle is binary | 552 "_\x02_" // a byte in the middle is binary |
558 )); | 553 )); |
559 | 554 |
560 } // namespace | 555 } // namespace |
561 } // namespace net | 556 } // namespace net |
OLD | NEW |