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

Side by Side Diff: content/browser/renderer_host/resource_dispatcher_host_unittest.cc

Issue 7847027: DownloadId (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: merge Created 9 years, 3 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 | Annotate | Revision Log
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 "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/file_path.h" 10 #include "base/file_path.h"
10 #include "base/message_loop.h" 11 #include "base/message_loop.h"
11 #include "base/process_util.h" 12 #include "base/process_util.h"
12 #include "content/browser/browser_thread.h" 13 #include "content/browser/browser_thread.h"
13 #include "content/browser/child_process_security_policy.h" 14 #include "content/browser/child_process_security_policy.h"
15 #include "content/browser/download/download_id.h"
14 #include "content/browser/mock_resource_context.h" 16 #include "content/browser/mock_resource_context.h"
15 #include "content/browser/renderer_host/dummy_resource_handler.h" 17 #include "content/browser/renderer_host/dummy_resource_handler.h"
16 #include "content/browser/renderer_host/global_request_id.h" 18 #include "content/browser/renderer_host/global_request_id.h"
17 #include "content/browser/renderer_host/resource_dispatcher_host.h" 19 #include "content/browser/renderer_host/resource_dispatcher_host.h"
18 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" 20 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
19 #include "content/browser/renderer_host/resource_handler.h" 21 #include "content/browser/renderer_host/resource_handler.h"
20 #include "content/browser/renderer_host/resource_message_filter.h" 22 #include "content/browser/renderer_host/resource_message_filter.h"
21 #include "content/common/resource_messages.h" 23 #include "content/common/resource_messages.h"
22 #include "content/common/resource_response.h" 24 #include "content/common/resource_response.h"
23 #include "content/common/view_messages.h" 25 #include "content/common/view_messages.h"
(...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 1128
1127 void* iter = NULL; 1129 void* iter = NULL;
1128 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); 1130 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id));
1129 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); 1131 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status));
1130 1132
1131 EXPECT_EQ(1, request_id); 1133 EXPECT_EQ(1, request_id);
1132 EXPECT_EQ(net::URLRequestStatus::CANCELED, status.status()); 1134 EXPECT_EQ(net::URLRequestStatus::CANCELED, status.status());
1133 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, status.error()); 1135 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, status.error());
1134 } 1136 }
1135 1137
1138 namespace {
1139 DownloadId MockNextDownloadId() {
1140 return DownloadId(reinterpret_cast<DownloadManager*>(0xFFFFFFFF), 0);
1141 }
1142 }
1143
1136 // Test for http://crbug.com/76202 . We don't want to destroy a 1144 // Test for http://crbug.com/76202 . We don't want to destroy a
1137 // download request prematurely when processing a cancellation from 1145 // download request prematurely when processing a cancellation from
1138 // the renderer. 1146 // the renderer.
1139 TEST_F(ResourceDispatcherHostTest, IgnoreCancelForDownloads) { 1147 TEST_F(ResourceDispatcherHostTest, IgnoreCancelForDownloads) {
1140 EXPECT_EQ(0, host_.pending_requests()); 1148 EXPECT_EQ(0, host_.pending_requests());
1141 1149
1142 int render_view_id = 0; 1150 int render_view_id = 0;
1143 int request_id = 1; 1151 int request_id = 1;
1144 1152
1145 std::string response("HTTP\n" 1153 std::string response("HTTP\n"
1146 "Content-disposition: attachment; filename=foo\n\n"); 1154 "Content-disposition: attachment; filename=foo\n\n");
1147 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), 1155 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(),
1148 response.size())); 1156 response.size()));
1149 std::string response_data("01234567890123456789\x01foobar"); 1157 std::string response_data("01234567890123456789\x01foobar");
1150 1158
1151 SetResponse(raw_headers, response_data); 1159 SetResponse(raw_headers, response_data);
1152 SetResourceType(ResourceType::MAIN_FRAME); 1160 SetResourceType(ResourceType::MAIN_FRAME);
1153 HandleScheme("http"); 1161 HandleScheme("http");
1154 1162
1155 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); 1163 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah"));
1164 content::MockResourceContext::GetInstance()->set_next_download_id_thunk(
1165 base::Bind(&MockNextDownloadId));
1156 // Return some data so that the request is identified as a download 1166 // Return some data so that the request is identified as a download
1157 // and the proper resource handlers are created. 1167 // and the proper resource handlers are created.
1158 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 1168 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
1159 1169
1160 // And now simulate a cancellation coming from the renderer. 1170 // And now simulate a cancellation coming from the renderer.
1161 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id); 1171 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id);
1162 bool msg_was_ok; 1172 bool msg_was_ok;
1163 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); 1173 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok);
1164 1174
1165 // Since the request had already started processing as a download, 1175 // Since the request had already started processing as a download,
(...skipping 15 matching lines...) Expand all
1181 "Content-disposition: attachment; filename=foo\n\n"); 1191 "Content-disposition: attachment; filename=foo\n\n");
1182 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), 1192 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(),
1183 response.size())); 1193 response.size()));
1184 std::string response_data("01234567890123456789\x01foobar"); 1194 std::string response_data("01234567890123456789\x01foobar");
1185 1195
1186 SetResponse(raw_headers, response_data); 1196 SetResponse(raw_headers, response_data);
1187 SetResourceType(ResourceType::MAIN_FRAME); 1197 SetResourceType(ResourceType::MAIN_FRAME);
1188 HandleScheme("http"); 1198 HandleScheme("http");
1189 1199
1190 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); 1200 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah"));
1201 content::MockResourceContext::GetInstance()->set_next_download_id_thunk(
1202 base::Bind(&MockNextDownloadId));
1191 // Return some data so that the request is identified as a download 1203 // Return some data so that the request is identified as a download
1192 // and the proper resource handlers are created. 1204 // and the proper resource handlers are created.
1193 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 1205 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
1194 1206
1195 // And now simulate a cancellation coming from the renderer. 1207 // And now simulate a cancellation coming from the renderer.
1196 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id); 1208 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id);
1197 bool msg_was_ok; 1209 bool msg_was_ok;
1198 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); 1210 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok);
1199 1211
1200 // Since the request had already started processing as a download, 1212 // Since the request had already started processing as a download,
1201 // the cancellation above should have been ignored and the request 1213 // the cancellation above should have been ignored and the request
1202 // should still be alive. 1214 // should still be alive.
1203 EXPECT_EQ(1, host_.pending_requests()); 1215 EXPECT_EQ(1, host_.pending_requests());
1204 1216
1205 // Cancelling by other methods shouldn't work either. 1217 // Cancelling by other methods shouldn't work either.
1206 host_.CancelRequestsForProcess(render_view_id); 1218 host_.CancelRequestsForProcess(render_view_id);
1207 EXPECT_EQ(1, host_.pending_requests()); 1219 EXPECT_EQ(1, host_.pending_requests());
1208 1220
1209 // Cancelling by context should work. 1221 // Cancelling by context should work.
1210 host_.CancelRequestsForContext(&filter_->resource_context()); 1222 host_.CancelRequestsForContext(&filter_->resource_context());
1211 EXPECT_EQ(0, host_.pending_requests()); 1223 EXPECT_EQ(0, host_.pending_requests());
1212 } 1224 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/resource_dispatcher_host.cc ('k') | content/browser/resource_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698