| 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 "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" | |
| 10 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 11 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 12 #include "base/process_util.h" | 11 #include "base/process_util.h" |
| 13 #include "content/browser/browser_thread.h" | 12 #include "content/browser/browser_thread.h" |
| 14 #include "content/browser/child_process_security_policy.h" | 13 #include "content/browser/child_process_security_policy.h" |
| 15 #include "content/browser/download/download_id.h" | |
| 16 #include "content/browser/mock_resource_context.h" | 14 #include "content/browser/mock_resource_context.h" |
| 17 #include "content/browser/renderer_host/global_request_id.h" | 15 #include "content/browser/renderer_host/global_request_id.h" |
| 18 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 16 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 19 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 17 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
| 20 #include "content/browser/renderer_host/resource_handler.h" | 18 #include "content/browser/renderer_host/resource_handler.h" |
| 21 #include "content/browser/renderer_host/resource_message_filter.h" | 19 #include "content/browser/renderer_host/resource_message_filter.h" |
| 22 #include "content/common/resource_messages.h" | 20 #include "content/common/resource_messages.h" |
| 23 #include "content/common/resource_response.h" | 21 #include "content/common/resource_response.h" |
| 24 #include "content/common/view_messages.h" | 22 #include "content/common/view_messages.h" |
| 25 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| (...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1126 | 1124 |
| 1127 void* iter = NULL; | 1125 void* iter = NULL; |
| 1128 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); | 1126 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); |
| 1129 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); | 1127 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); |
| 1130 | 1128 |
| 1131 EXPECT_EQ(1, request_id); | 1129 EXPECT_EQ(1, request_id); |
| 1132 EXPECT_EQ(net::URLRequestStatus::CANCELED, status.status()); | 1130 EXPECT_EQ(net::URLRequestStatus::CANCELED, status.status()); |
| 1133 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, status.os_error()); | 1131 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, status.os_error()); |
| 1134 } | 1132 } |
| 1135 | 1133 |
| 1136 namespace { | |
| 1137 DownloadId MockNextDownloadId() { | |
| 1138 return DownloadId(reinterpret_cast<DownloadManager*>(0xFFFFFFFF), 0); | |
| 1139 } | |
| 1140 } | |
| 1141 | |
| 1142 // Test for http://crbug.com/76202 . We don't want to destroy a | 1134 // Test for http://crbug.com/76202 . We don't want to destroy a |
| 1143 // download request prematurely when processing a cancellation from | 1135 // download request prematurely when processing a cancellation from |
| 1144 // the renderer. | 1136 // the renderer. |
| 1145 TEST_F(ResourceDispatcherHostTest, IgnoreCancelForDownloads) { | 1137 TEST_F(ResourceDispatcherHostTest, IgnoreCancelForDownloads) { |
| 1146 EXPECT_EQ(0, host_.pending_requests()); | 1138 EXPECT_EQ(0, host_.pending_requests()); |
| 1147 | 1139 |
| 1148 int render_view_id = 0; | 1140 int render_view_id = 0; |
| 1149 int request_id = 1; | 1141 int request_id = 1; |
| 1150 | 1142 |
| 1151 std::string response("HTTP\n" | 1143 std::string response("HTTP\n" |
| 1152 "Content-disposition: attachment; filename=foo\n\n"); | 1144 "Content-disposition: attachment; filename=foo\n\n"); |
| 1153 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), | 1145 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), |
| 1154 response.size())); | 1146 response.size())); |
| 1155 std::string response_data("01234567890123456789\x01foobar"); | 1147 std::string response_data("01234567890123456789\x01foobar"); |
| 1156 | 1148 |
| 1157 SetResponse(raw_headers, response_data); | 1149 SetResponse(raw_headers, response_data); |
| 1158 SetResourceType(ResourceType::MAIN_FRAME); | 1150 SetResourceType(ResourceType::MAIN_FRAME); |
| 1159 HandleScheme("http"); | 1151 HandleScheme("http"); |
| 1160 | 1152 |
| 1161 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1153 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); |
| 1162 content::MockResourceContext::GetInstance()->set_next_download_id_thunk( | |
| 1163 base::Bind(&MockNextDownloadId)); | |
| 1164 // Return some data so that the request is identified as a download | 1154 // Return some data so that the request is identified as a download |
| 1165 // and the proper resource handlers are created. | 1155 // and the proper resource handlers are created. |
| 1166 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 1156 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
| 1167 | 1157 |
| 1168 // And now simulate a cancellation coming from the renderer. | 1158 // And now simulate a cancellation coming from the renderer. |
| 1169 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id); | 1159 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id); |
| 1170 bool msg_was_ok; | 1160 bool msg_was_ok; |
| 1171 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); | 1161 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); |
| 1172 | 1162 |
| 1173 // Since the request had already started processing as a download, | 1163 // Since the request had already started processing as a download, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1189 "Content-disposition: attachment; filename=foo\n\n"); | 1179 "Content-disposition: attachment; filename=foo\n\n"); |
| 1190 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), | 1180 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), |
| 1191 response.size())); | 1181 response.size())); |
| 1192 std::string response_data("01234567890123456789\x01foobar"); | 1182 std::string response_data("01234567890123456789\x01foobar"); |
| 1193 | 1183 |
| 1194 SetResponse(raw_headers, response_data); | 1184 SetResponse(raw_headers, response_data); |
| 1195 SetResourceType(ResourceType::MAIN_FRAME); | 1185 SetResourceType(ResourceType::MAIN_FRAME); |
| 1196 HandleScheme("http"); | 1186 HandleScheme("http"); |
| 1197 | 1187 |
| 1198 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1188 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); |
| 1199 content::MockResourceContext::GetInstance()->set_next_download_id_thunk( | |
| 1200 base::Bind(&MockNextDownloadId)); | |
| 1201 // Return some data so that the request is identified as a download | 1189 // Return some data so that the request is identified as a download |
| 1202 // and the proper resource handlers are created. | 1190 // and the proper resource handlers are created. |
| 1203 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 1191 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
| 1204 | 1192 |
| 1205 // And now simulate a cancellation coming from the renderer. | 1193 // And now simulate a cancellation coming from the renderer. |
| 1206 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id); | 1194 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id); |
| 1207 bool msg_was_ok; | 1195 bool msg_was_ok; |
| 1208 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); | 1196 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); |
| 1209 | 1197 |
| 1210 // Since the request had already started processing as a download, | 1198 // Since the request had already started processing as a download, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1255 const net::URLRequestStatus& status, | 1243 const net::URLRequestStatus& status, |
| 1256 const std::string& info) { | 1244 const std::string& info) { |
| 1257 return true; | 1245 return true; |
| 1258 } | 1246 } |
| 1259 | 1247 |
| 1260 void OnRequestClosed() {} | 1248 void OnRequestClosed() {} |
| 1261 | 1249 |
| 1262 private: | 1250 private: |
| 1263 DISALLOW_COPY_AND_ASSIGN(DummyResourceHandler); | 1251 DISALLOW_COPY_AND_ASSIGN(DummyResourceHandler); |
| 1264 }; | 1252 }; |
| OLD | NEW |