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

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

Issue 2883833002: net: Do not sniff XHTML content (Closed)
Patch Set: . Created 3 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 unified diff | Download patch
OLDNEW
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
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 // Positive test for the one instance we upgrade to XHTML.
343 EXPECT_EQ("application/xhtml+xml", 343 EXPECT_EQ("application/xhtml+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(),
346 "text/xml")); 346 "text/xml"));
347 EXPECT_EQ("application/xhtml+xml",
348 SniffMimeType("<html xmlns=\"http://www.w3.org/1999/xhtml\">",
349 std::string(),
350 "application/xml"));
351 347
352 // Following our behavior with HTML, don't call other mime types XHTML. 348 // Following our behavior with HTML, don't call other mime types XHTML.
349 EXPECT_EQ("application/xml",
350 SniffMimeType("<html xmlns=\"http://www.w3.org/1999/xhtml\">",
351 std::string(), "application/xml"));
353 EXPECT_EQ("text/plain", 352 EXPECT_EQ("text/plain",
354 SniffMimeType("<html xmlns=\"http://www.w3.org/1999/xhtml\">", 353 SniffMimeType("<html xmlns=\"http://www.w3.org/1999/xhtml\">",
355 std::string(), 354 std::string(),
356 "text/plain")); 355 "text/plain"));
357 EXPECT_EQ("application/rss+xml", 356 EXPECT_EQ("application/rss+xml",
358 SniffMimeType("<html xmlns=\"http://www.w3.org/1999/xhtml\">", 357 SniffMimeType("<html xmlns=\"http://www.w3.org/1999/xhtml\">",
359 std::string(), 358 std::string(),
360 "application/rss+xml")); 359 "application/rss+xml"));
361 360
362 // Don't sniff other HTML-looking bits as HTML. 361 // Don't sniff other HTML-looking bits as HTML.
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 551
553 INSTANTIATE_TEST_CASE_P(MimeSnifferControlCodesEdgeCaseTest, 552 INSTANTIATE_TEST_CASE_P(MimeSnifferControlCodesEdgeCaseTest,
554 MimeSnifferControlCodesEdgeCaseTest, 553 MimeSnifferControlCodesEdgeCaseTest,
555 Values("\x01__", // first byte is binary 554 Values("\x01__", // first byte is binary
556 "__\x03", // last byte is binary 555 "__\x03", // last byte is binary
557 "_\x02_" // a byte in the middle is binary 556 "_\x02_" // a byte in the middle is binary
558 )); 557 ));
559 558
560 } // namespace 559 } // namespace
561 } // namespace net 560 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698