| 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.h" | 5 #include "content/browser/renderer_host/resource_dispatcher_host.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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 namespace { | 48 namespace { |
| 49 | 49 |
| 50 // Returns the resource response header structure for this request. | 50 // Returns the resource response header structure for this request. |
| 51 void GetResponseHead(const std::vector<IPC::Message>& messages, | 51 void GetResponseHead(const std::vector<IPC::Message>& messages, |
| 52 content::ResourceResponseHead* response_head) { | 52 content::ResourceResponseHead* response_head) { |
| 53 ASSERT_GE(messages.size(), 2U); | 53 ASSERT_GE(messages.size(), 2U); |
| 54 | 54 |
| 55 // The first messages should be received response. | 55 // The first messages should be received response. |
| 56 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type()); | 56 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type()); |
| 57 | 57 |
| 58 void* iter = NULL; | 58 PickleIterator iter(messages[0]); |
| 59 int request_id; | 59 int request_id; |
| 60 ASSERT_TRUE(IPC::ReadParam(&messages[0], &iter, &request_id)); | 60 ASSERT_TRUE(IPC::ReadParam(&messages[0], &iter, &request_id)); |
| 61 ASSERT_TRUE(IPC::ReadParam(&messages[0], &iter, response_head)); | 61 ASSERT_TRUE(IPC::ReadParam(&messages[0], &iter, response_head)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 } // namespace | 64 } // namespace |
| 65 | 65 |
| 66 static int RequestIDForMessage(const IPC::Message& msg) { | 66 static int RequestIDForMessage(const IPC::Message& msg) { |
| 67 int request_id = -1; | 67 int request_id = -1; |
| 68 switch (msg.type()) { | 68 switch (msg.type()) { |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 // are appropriate. | 532 // are appropriate. |
| 533 ASSERT_EQ(3U, messages.size()); | 533 ASSERT_EQ(3U, messages.size()); |
| 534 | 534 |
| 535 // The first messages should be received response | 535 // The first messages should be received response |
| 536 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type()); | 536 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type()); |
| 537 | 537 |
| 538 // followed by the data, currently we only do the data in one chunk, but | 538 // followed by the data, currently we only do the data in one chunk, but |
| 539 // should probably test multiple chunks later | 539 // should probably test multiple chunks later |
| 540 ASSERT_EQ(ResourceMsg_DataReceived::ID, messages[1].type()); | 540 ASSERT_EQ(ResourceMsg_DataReceived::ID, messages[1].type()); |
| 541 | 541 |
| 542 void* iter = NULL; | 542 PickleIterator iter(messages[1]); |
| 543 int request_id; | 543 int request_id; |
| 544 ASSERT_TRUE(IPC::ReadParam(&messages[1], &iter, &request_id)); | 544 ASSERT_TRUE(IPC::ReadParam(&messages[1], &iter, &request_id)); |
| 545 base::SharedMemoryHandle shm_handle; | 545 base::SharedMemoryHandle shm_handle; |
| 546 ASSERT_TRUE(IPC::ReadParam(&messages[1], &iter, &shm_handle)); | 546 ASSERT_TRUE(IPC::ReadParam(&messages[1], &iter, &shm_handle)); |
| 547 uint32 data_len; | 547 uint32 data_len; |
| 548 ASSERT_TRUE(IPC::ReadParam(&messages[1], &iter, &data_len)); | 548 ASSERT_TRUE(IPC::ReadParam(&messages[1], &iter, &data_len)); |
| 549 | 549 |
| 550 ASSERT_EQ(reference_data.size(), data_len); | 550 ASSERT_EQ(reference_data.size(), data_len); |
| 551 base::SharedMemory shared_mem(shm_handle, true); // read only | 551 base::SharedMemory shared_mem(shm_handle, true); // read only |
| 552 shared_mem.Map(data_len); | 552 shared_mem.Map(data_len); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 CheckSuccessfulRequest(msgs[2], net::URLRequestTestJob::test_data_3()); | 611 CheckSuccessfulRequest(msgs[2], net::URLRequestTestJob::test_data_3()); |
| 612 | 612 |
| 613 // Check that request 2 got canceled. | 613 // Check that request 2 got canceled. |
| 614 ASSERT_EQ(2U, msgs[1].size()); | 614 ASSERT_EQ(2U, msgs[1].size()); |
| 615 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type()); | 615 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type()); |
| 616 ASSERT_EQ(ResourceMsg_RequestComplete::ID, msgs[1][1].type()); | 616 ASSERT_EQ(ResourceMsg_RequestComplete::ID, msgs[1][1].type()); |
| 617 | 617 |
| 618 int request_id; | 618 int request_id; |
| 619 net::URLRequestStatus status; | 619 net::URLRequestStatus status; |
| 620 | 620 |
| 621 void* iter = NULL; | 621 PickleIterator iter(msgs[1][1]); |
| 622 ASSERT_TRUE(IPC::ReadParam(&msgs[1][1], &iter, &request_id)); | 622 ASSERT_TRUE(IPC::ReadParam(&msgs[1][1], &iter, &request_id)); |
| 623 ASSERT_TRUE(IPC::ReadParam(&msgs[1][1], &iter, &status)); | 623 ASSERT_TRUE(IPC::ReadParam(&msgs[1][1], &iter, &status)); |
| 624 | 624 |
| 625 EXPECT_EQ(net::URLRequestStatus::CANCELED, status.status()); | 625 EXPECT_EQ(net::URLRequestStatus::CANCELED, status.status()); |
| 626 } | 626 } |
| 627 | 627 |
| 628 TEST_F(ResourceDispatcherHostTest, CancelWhileStartIsDeferred) { | 628 TEST_F(ResourceDispatcherHostTest, CancelWhileStartIsDeferred) { |
| 629 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(0)); | 629 EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(0)); |
| 630 | 630 |
| 631 bool was_deleted = false; | 631 bool was_deleted = false; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 ASSERT_EQ(1U, msgs.size()); | 688 ASSERT_EQ(1U, msgs.size()); |
| 689 | 689 |
| 690 // Check that request 1 got canceled. | 690 // Check that request 1 got canceled. |
| 691 ASSERT_EQ(2U, msgs[0].size()); | 691 ASSERT_EQ(2U, msgs[0].size()); |
| 692 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); | 692 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); |
| 693 ASSERT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][1].type()); | 693 ASSERT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][1].type()); |
| 694 | 694 |
| 695 int request_id; | 695 int request_id; |
| 696 net::URLRequestStatus status; | 696 net::URLRequestStatus status; |
| 697 | 697 |
| 698 void* iter = NULL; | 698 PickleIterator iter(msgs[0][1]); |
| 699 ASSERT_TRUE(IPC::ReadParam(&msgs[0][1], &iter, &request_id)); | 699 ASSERT_TRUE(IPC::ReadParam(&msgs[0][1], &iter, &request_id)); |
| 700 ASSERT_TRUE(IPC::ReadParam(&msgs[0][1], &iter, &status)); | 700 ASSERT_TRUE(IPC::ReadParam(&msgs[0][1], &iter, &status)); |
| 701 | 701 |
| 702 EXPECT_EQ(net::URLRequestStatus::CANCELED, status.status()); | 702 EXPECT_EQ(net::URLRequestStatus::CANCELED, status.status()); |
| 703 } | 703 } |
| 704 | 704 |
| 705 // The host delegate acts as a second one so we can have some requests | 705 // The host delegate acts as a second one so we can have some requests |
| 706 // pending and some canceled. | 706 // pending and some canceled. |
| 707 class TestFilter : public ForwardingFilter { | 707 class TestFilter : public ForwardingFilter { |
| 708 public: | 708 public: |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1062 // Should have sent a single RequestComplete message. | 1062 // Should have sent a single RequestComplete message. |
| 1063 int index = kMaxRequests + i; | 1063 int index = kMaxRequests + i; |
| 1064 EXPECT_EQ(1U, msgs[index].size()); | 1064 EXPECT_EQ(1U, msgs[index].size()); |
| 1065 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[index][0].type()); | 1065 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[index][0].type()); |
| 1066 | 1066 |
| 1067 // The RequestComplete message should have had status | 1067 // The RequestComplete message should have had status |
| 1068 // (CANCELLED, ERR_INSUFFICIENT_RESOURCES). | 1068 // (CANCELLED, ERR_INSUFFICIENT_RESOURCES). |
| 1069 int request_id; | 1069 int request_id; |
| 1070 net::URLRequestStatus status; | 1070 net::URLRequestStatus status; |
| 1071 | 1071 |
| 1072 void* iter = NULL; | 1072 PickleIterator iter(msgs[index][0]); |
| 1073 EXPECT_TRUE(IPC::ReadParam(&msgs[index][0], &iter, &request_id)); | 1073 EXPECT_TRUE(IPC::ReadParam(&msgs[index][0], &iter, &request_id)); |
| 1074 EXPECT_TRUE(IPC::ReadParam(&msgs[index][0], &iter, &status)); | 1074 EXPECT_TRUE(IPC::ReadParam(&msgs[index][0], &iter, &status)); |
| 1075 | 1075 |
| 1076 EXPECT_EQ(index + 1, request_id); | 1076 EXPECT_EQ(index + 1, request_id); |
| 1077 EXPECT_EQ(net::URLRequestStatus::CANCELED, status.status()); | 1077 EXPECT_EQ(net::URLRequestStatus::CANCELED, status.status()); |
| 1078 EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, status.error()); | 1078 EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, status.error()); |
| 1079 } | 1079 } |
| 1080 | 1080 |
| 1081 // The final 2 requests should have succeeded. | 1081 // The final 2 requests should have succeeded. |
| 1082 CheckSuccessfulRequest(msgs[kMaxRequests + 2], | 1082 CheckSuccessfulRequest(msgs[kMaxRequests + 2], |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 | 1226 |
| 1227 // We should have gotten one RequestComplete message. | 1227 // We should have gotten one RequestComplete message. |
| 1228 ASSERT_EQ(1U, msgs[0].size()); | 1228 ASSERT_EQ(1U, msgs[0].size()); |
| 1229 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); | 1229 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); |
| 1230 | 1230 |
| 1231 // The RequestComplete message should have had status | 1231 // The RequestComplete message should have had status |
| 1232 // (CANCELED, ERR_FILE_NOT_FOUND). | 1232 // (CANCELED, ERR_FILE_NOT_FOUND). |
| 1233 int request_id; | 1233 int request_id; |
| 1234 net::URLRequestStatus status; | 1234 net::URLRequestStatus status; |
| 1235 | 1235 |
| 1236 void* iter = NULL; | 1236 PickleIterator iter(msgs[0][0]); |
| 1237 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); | 1237 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); |
| 1238 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); | 1238 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); |
| 1239 | 1239 |
| 1240 EXPECT_EQ(1, request_id); | 1240 EXPECT_EQ(1, request_id); |
| 1241 EXPECT_EQ(net::URLRequestStatus::CANCELED, status.status()); | 1241 EXPECT_EQ(net::URLRequestStatus::CANCELED, status.status()); |
| 1242 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, status.error()); | 1242 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, status.error()); |
| 1243 } | 1243 } |
| 1244 | 1244 |
| 1245 // Test for http://crbug.com/76202 . We don't want to destroy a | 1245 // Test for http://crbug.com/76202 . We don't want to destroy a |
| 1246 // download request prematurely when processing a cancellation from | 1246 // download request prematurely when processing a cancellation from |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1380 | 1380 |
| 1381 // We should have gotten one RequestComplete message. | 1381 // We should have gotten one RequestComplete message. |
| 1382 ASSERT_EQ(1U, msgs[0].size()); | 1382 ASSERT_EQ(1U, msgs[0].size()); |
| 1383 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); | 1383 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); |
| 1384 | 1384 |
| 1385 // The RequestComplete message should have had status | 1385 // The RequestComplete message should have had status |
| 1386 // (FAILED, ERR_UNKNOWN_URL_SCHEME). | 1386 // (FAILED, ERR_UNKNOWN_URL_SCHEME). |
| 1387 int request_id; | 1387 int request_id; |
| 1388 net::URLRequestStatus status; | 1388 net::URLRequestStatus status; |
| 1389 | 1389 |
| 1390 void* iter = NULL; | 1390 PickleIterator iter(msgs[0][0]); |
| 1391 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); | 1391 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); |
| 1392 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); | 1392 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); |
| 1393 | 1393 |
| 1394 EXPECT_EQ(1, request_id); | 1394 EXPECT_EQ(1, request_id); |
| 1395 EXPECT_EQ(net::URLRequestStatus::FAILED, status.status()); | 1395 EXPECT_EQ(net::URLRequestStatus::FAILED, status.status()); |
| 1396 EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME, status.error()); | 1396 EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME, status.error()); |
| 1397 } | 1397 } |
| OLD | NEW |