| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/resource_dispatcher_host_impl.h" | 5 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1246 accum_.GetClassifiedMessages(&msgs); | 1246 accum_.GetClassifiedMessages(&msgs); |
| 1247 ASSERT_EQ(1U, msgs.size()); | 1247 ASSERT_EQ(1U, msgs.size()); |
| 1248 | 1248 |
| 1249 content::ResourceResponseHead response_head; | 1249 content::ResourceResponseHead response_head; |
| 1250 GetResponseHead(msgs[0], &response_head); | 1250 GetResponseHead(msgs[0], &response_head); |
| 1251 ASSERT_EQ("image/jpeg", response_head.mime_type); | 1251 ASSERT_EQ("image/jpeg", response_head.mime_type); |
| 1252 } | 1252 } |
| 1253 | 1253 |
| 1254 // Tests that we don't sniff the mime type when there is no message body. | 1254 // Tests that we don't sniff the mime type when there is no message body. |
| 1255 TEST_F(ResourceDispatcherHostTest, MimeNotSniffed2) { | 1255 TEST_F(ResourceDispatcherHostTest, MimeNotSniffed2) { |
| 1256 |
| 1256 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(0)); | 1257 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(0)); |
| 1257 | 1258 |
| 1258 std::string response("HTTP/1.1 304 Not Modified\n\n"); | 1259 std::string response("HTTP/1.1 304 Not Modified\n\n"); |
| 1259 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), | 1260 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), |
| 1260 response.size())); | 1261 response.size())); |
| 1261 std::string response_data; | 1262 std::string response_data; |
| 1262 SetResponse(raw_headers, response_data); | 1263 SetResponse(raw_headers, response_data); |
| 1263 | 1264 |
| 1264 HandleScheme("http"); | 1265 HandleScheme("http"); |
| 1265 MakeTestRequest(0, 1, GURL("http:bla")); | 1266 MakeTestRequest(0, 1, GURL("http:bla")); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1299 // Sorts out all the messages we saw by request. | 1300 // Sorts out all the messages we saw by request. |
| 1300 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1301 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1301 accum_.GetClassifiedMessages(&msgs); | 1302 accum_.GetClassifiedMessages(&msgs); |
| 1302 ASSERT_EQ(1U, msgs.size()); | 1303 ASSERT_EQ(1U, msgs.size()); |
| 1303 | 1304 |
| 1304 content::ResourceResponseHead response_head; | 1305 content::ResourceResponseHead response_head; |
| 1305 GetResponseHead(msgs[0], &response_head); | 1306 GetResponseHead(msgs[0], &response_head); |
| 1306 ASSERT_EQ("text/plain", response_head.mime_type); | 1307 ASSERT_EQ("text/plain", response_head.mime_type); |
| 1307 } | 1308 } |
| 1308 | 1309 |
| 1310 TEST_F(ResourceDispatcherHostTest, MimeSniffEmpty) { |
| 1311 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(0)); |
| 1312 |
| 1313 std::string response("HTTP/1.1 200 OK\n\n"); |
| 1314 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), |
| 1315 response.size())); |
| 1316 std::string response_data; |
| 1317 SetResponse(raw_headers, response_data); |
| 1318 |
| 1319 HandleScheme("http"); |
| 1320 MakeTestRequest(0, 1, GURL("http:bla")); |
| 1321 |
| 1322 // Flush all pending requests. |
| 1323 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1324 |
| 1325 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(0)); |
| 1326 |
| 1327 // Sorts out all the messages we saw by request. |
| 1328 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1329 accum_.GetClassifiedMessages(&msgs); |
| 1330 ASSERT_EQ(1U, msgs.size()); |
| 1331 |
| 1332 content::ResourceResponseHead response_head; |
| 1333 GetResponseHead(msgs[0], &response_head); |
| 1334 ASSERT_EQ("text/plain", response_head.mime_type); |
| 1335 } |
| 1336 |
| 1309 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream). | 1337 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream). |
| 1310 TEST_F(ResourceDispatcherHostTest, ForbiddenDownload) { | 1338 TEST_F(ResourceDispatcherHostTest, ForbiddenDownload) { |
| 1311 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(0)); | 1339 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(0)); |
| 1312 | 1340 |
| 1313 std::string response("HTTP/1.1 403 Forbidden\n" | 1341 std::string response("HTTP/1.1 403 Forbidden\n" |
| 1314 "Content-disposition: attachment; filename=blah\n" | 1342 "Content-disposition: attachment; filename=blah\n" |
| 1315 "Content-type: application/octet-stream\n\n"); | 1343 "Content-type: application/octet-stream\n\n"); |
| 1316 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), | 1344 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), |
| 1317 response.size())); | 1345 response.size())); |
| 1318 std::string response_data("<html><title>Test One</title></html>"); | 1346 std::string response_data("<html><title>Test One</title></html>"); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1573 } | 1601 } |
| 1574 | 1602 |
| 1575 MessageLoop::current()->RunAllPending(); | 1603 MessageLoop::current()->RunAllPending(); |
| 1576 | 1604 |
| 1577 msgs.clear(); | 1605 msgs.clear(); |
| 1578 accum_.GetClassifiedMessages(&msgs); | 1606 accum_.GetClassifiedMessages(&msgs); |
| 1579 } | 1607 } |
| 1580 } | 1608 } |
| 1581 | 1609 |
| 1582 } // namespace content | 1610 } // namespace content |
| OLD | NEW |