| 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 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 | 763 |
| 764 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); | 764 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); |
| 765 CheckSuccessfulRequest(msgs[2], net::URLRequestTestJob::test_data_3()); | 765 CheckSuccessfulRequest(msgs[2], net::URLRequestTestJob::test_data_3()); |
| 766 | 766 |
| 767 // Check that request 2 got canceled. | 767 // Check that request 2 got canceled. |
| 768 ASSERT_EQ(2U, msgs[1].size()); | 768 ASSERT_EQ(2U, msgs[1].size()); |
| 769 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type()); | 769 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type()); |
| 770 ASSERT_EQ(ResourceMsg_RequestComplete::ID, msgs[1][1].type()); | 770 ASSERT_EQ(ResourceMsg_RequestComplete::ID, msgs[1][1].type()); |
| 771 | 771 |
| 772 int request_id; | 772 int request_id; |
| 773 net::URLRequestStatus status; | 773 int error_code; |
| 774 | 774 |
| 775 PickleIterator iter(msgs[1][1]); | 775 PickleIterator iter(msgs[1][1]); |
| 776 ASSERT_TRUE(IPC::ReadParam(&msgs[1][1], &iter, &request_id)); | 776 ASSERT_TRUE(IPC::ReadParam(&msgs[1][1], &iter, &request_id)); |
| 777 ASSERT_TRUE(IPC::ReadParam(&msgs[1][1], &iter, &status)); | 777 ASSERT_TRUE(IPC::ReadParam(&msgs[1][1], &iter, &error_code)); |
| 778 | 778 |
| 779 EXPECT_EQ(net::URLRequestStatus::CANCELED, status.status()); | 779 EXPECT_EQ(net::ERR_ABORTED, error_code); |
| 780 } | 780 } |
| 781 | 781 |
| 782 TEST_F(ResourceDispatcherHostTest, CancelWhileStartIsDeferred) { | 782 TEST_F(ResourceDispatcherHostTest, CancelWhileStartIsDeferred) { |
| 783 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(0)); | 783 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(0)); |
| 784 | 784 |
| 785 bool was_deleted = false; | 785 bool was_deleted = false; |
| 786 | 786 |
| 787 // Arrange to have requests deferred before starting. | 787 // Arrange to have requests deferred before starting. |
| 788 TestResourceDispatcherHostDelegate delegate; | 788 TestResourceDispatcherHostDelegate delegate; |
| 789 delegate.set_defer_flags(DEFER_STARTING_REQUEST); | 789 delegate.set_defer_flags(DEFER_STARTING_REQUEST); |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 CheckSuccessfulRequest(msgs[i], net::URLRequestTestJob::test_data_2()); | 1192 CheckSuccessfulRequest(msgs[i], net::URLRequestTestJob::test_data_2()); |
| 1193 | 1193 |
| 1194 // Check that the subsequent two requests (kMaxRequests + 1) and | 1194 // Check that the subsequent two requests (kMaxRequests + 1) and |
| 1195 // (kMaxRequests + 2) were failed, since the per-process bound was reached. | 1195 // (kMaxRequests + 2) were failed, since the per-process bound was reached. |
| 1196 for (int i = 0; i < 2; ++i) { | 1196 for (int i = 0; i < 2; ++i) { |
| 1197 // Should have sent a single RequestComplete message. | 1197 // Should have sent a single RequestComplete message. |
| 1198 int index = kMaxRequests + i; | 1198 int index = kMaxRequests + i; |
| 1199 EXPECT_EQ(1U, msgs[index].size()); | 1199 EXPECT_EQ(1U, msgs[index].size()); |
| 1200 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[index][0].type()); | 1200 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[index][0].type()); |
| 1201 | 1201 |
| 1202 // The RequestComplete message should have had status | 1202 // The RequestComplete message should have the error code of |
| 1203 // (CANCELLED, ERR_INSUFFICIENT_RESOURCES). | 1203 // ERR_INSUFFICIENT_RESOURCES. |
| 1204 int request_id; | 1204 int request_id; |
| 1205 net::URLRequestStatus status; | 1205 int error_code; |
| 1206 | 1206 |
| 1207 PickleIterator iter(msgs[index][0]); | 1207 PickleIterator iter(msgs[index][0]); |
| 1208 EXPECT_TRUE(IPC::ReadParam(&msgs[index][0], &iter, &request_id)); | 1208 EXPECT_TRUE(IPC::ReadParam(&msgs[index][0], &iter, &request_id)); |
| 1209 EXPECT_TRUE(IPC::ReadParam(&msgs[index][0], &iter, &status)); | 1209 EXPECT_TRUE(IPC::ReadParam(&msgs[index][0], &iter, &error_code)); |
| 1210 | 1210 |
| 1211 EXPECT_EQ(index + 1, request_id); | 1211 EXPECT_EQ(index + 1, request_id); |
| 1212 EXPECT_EQ(net::URLRequestStatus::CANCELED, status.status()); | 1212 EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, error_code); |
| 1213 EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, status.error()); | |
| 1214 } | 1213 } |
| 1215 | 1214 |
| 1216 // The final 2 requests should have succeeded. | 1215 // The final 2 requests should have succeeded. |
| 1217 CheckSuccessfulRequest(msgs[kMaxRequests + 2], | 1216 CheckSuccessfulRequest(msgs[kMaxRequests + 2], |
| 1218 net::URLRequestTestJob::test_data_2()); | 1217 net::URLRequestTestJob::test_data_2()); |
| 1219 CheckSuccessfulRequest(msgs[kMaxRequests + 3], | 1218 CheckSuccessfulRequest(msgs[kMaxRequests + 3], |
| 1220 net::URLRequestTestJob::test_data_2()); | 1219 net::URLRequestTestJob::test_data_2()); |
| 1221 } | 1220 } |
| 1222 | 1221 |
| 1223 // Tests that we sniff the mime type for a simple request. | 1222 // Tests that we sniff the mime type for a simple request. |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1366 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(0)); | 1365 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(0)); |
| 1367 | 1366 |
| 1368 // Sorts out all the messages we saw by request. | 1367 // Sorts out all the messages we saw by request. |
| 1369 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1368 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1370 accum_.GetClassifiedMessages(&msgs); | 1369 accum_.GetClassifiedMessages(&msgs); |
| 1371 | 1370 |
| 1372 // We should have gotten one RequestComplete message. | 1371 // We should have gotten one RequestComplete message. |
| 1373 ASSERT_EQ(1U, msgs[0].size()); | 1372 ASSERT_EQ(1U, msgs[0].size()); |
| 1374 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); | 1373 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); |
| 1375 | 1374 |
| 1376 // The RequestComplete message should have had status | 1375 // The RequestComplete message should have had the error code of |
| 1377 // (CANCELED, ERR_FILE_NOT_FOUND). | 1376 // ERR_FILE_NOT_FOUND. |
| 1378 int request_id; | 1377 int request_id; |
| 1379 net::URLRequestStatus status; | 1378 int error_code; |
| 1380 | 1379 |
| 1381 PickleIterator iter(msgs[0][0]); | 1380 PickleIterator iter(msgs[0][0]); |
| 1382 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); | 1381 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); |
| 1383 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); | 1382 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &error_code)); |
| 1384 | 1383 |
| 1385 EXPECT_EQ(1, request_id); | 1384 EXPECT_EQ(1, request_id); |
| 1386 EXPECT_EQ(net::URLRequestStatus::CANCELED, status.status()); | 1385 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, error_code); |
| 1387 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, status.error()); | |
| 1388 } | 1386 } |
| 1389 | 1387 |
| 1390 // Test for http://crbug.com/76202 . We don't want to destroy a | 1388 // Test for http://crbug.com/76202 . We don't want to destroy a |
| 1391 // download request prematurely when processing a cancellation from | 1389 // download request prematurely when processing a cancellation from |
| 1392 // the renderer. | 1390 // the renderer. |
| 1393 TEST_F(ResourceDispatcherHostTest, IgnoreCancelForDownloads) { | 1391 TEST_F(ResourceDispatcherHostTest, IgnoreCancelForDownloads) { |
| 1394 EXPECT_EQ(0, host_.pending_requests()); | 1392 EXPECT_EQ(0, host_.pending_requests()); |
| 1395 | 1393 |
| 1396 int render_view_id = 0; | 1394 int render_view_id = 0; |
| 1397 int request_id = 1; | 1395 int request_id = 1; |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1668 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1666 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1669 | 1667 |
| 1670 // Sort all the messages we saw by request. | 1668 // Sort all the messages we saw by request. |
| 1671 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1669 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1672 accum_.GetClassifiedMessages(&msgs); | 1670 accum_.GetClassifiedMessages(&msgs); |
| 1673 | 1671 |
| 1674 // We should have gotten one RequestComplete message. | 1672 // We should have gotten one RequestComplete message. |
| 1675 ASSERT_EQ(1U, msgs[0].size()); | 1673 ASSERT_EQ(1U, msgs[0].size()); |
| 1676 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); | 1674 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); |
| 1677 | 1675 |
| 1678 // The RequestComplete message should have had status | 1676 // The RequestComplete message should have the error code of |
| 1679 // (FAILED, ERR_UNKNOWN_URL_SCHEME). | 1677 // ERR_UNKNOWN_URL_SCHEME. |
| 1680 int request_id; | 1678 int request_id; |
| 1681 net::URLRequestStatus status; | 1679 int error_code; |
| 1682 | 1680 |
| 1683 PickleIterator iter(msgs[0][0]); | 1681 PickleIterator iter(msgs[0][0]); |
| 1684 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); | 1682 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); |
| 1685 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); | 1683 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &error_code)); |
| 1686 | 1684 |
| 1687 EXPECT_EQ(1, request_id); | 1685 EXPECT_EQ(1, request_id); |
| 1688 EXPECT_EQ(net::URLRequestStatus::FAILED, status.status()); | 1686 EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME, error_code); |
| 1689 EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME, status.error()); | |
| 1690 } | 1687 } |
| 1691 | 1688 |
| 1692 TEST_F(ResourceDispatcherHostTest, DataReceivedACKs) { | 1689 TEST_F(ResourceDispatcherHostTest, DataReceivedACKs) { |
| 1693 EXPECT_EQ(0, host_.pending_requests()); | 1690 EXPECT_EQ(0, host_.pending_requests()); |
| 1694 | 1691 |
| 1695 SendDataReceivedACKs(true); | 1692 SendDataReceivedACKs(true); |
| 1696 | 1693 |
| 1697 HandleScheme("big-job"); | 1694 HandleScheme("big-job"); |
| 1698 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); | 1695 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); |
| 1699 | 1696 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1747 } | 1744 } |
| 1748 | 1745 |
| 1749 MessageLoop::current()->RunAllPending(); | 1746 MessageLoop::current()->RunAllPending(); |
| 1750 | 1747 |
| 1751 msgs.clear(); | 1748 msgs.clear(); |
| 1752 accum_.GetClassifiedMessages(&msgs); | 1749 accum_.GetClassifiedMessages(&msgs); |
| 1753 } | 1750 } |
| 1754 } | 1751 } |
| 1755 | 1752 |
| 1756 } // namespace content | 1753 } // namespace content |
| OLD | NEW |